Another method using regex (this is more correct than Zachary's answer):
var string1 = 'someText', string2 = 'SometexT', regex = new RegExp('^' + string1 + '$', 'i'); if (regex.test(string2)) { return true; }
RegExp.test () will return true or false.
Also, by adding '^' (indicating the beginning of a line) to the beginning and '$' (indicating the end of a line) to the end, make sure your regular expression matches only if “sometext” is the only text in stringToTest. If you are looking for text that contains a regular expression, it is normal to leave them turned off.
It is just easier to use the string.toLowerCase () method.
So ... regular expressions are powerful, but you should only use them if you understand how they work. Unexpected things can happen when you use something you don’t understand.
There are tons of regular 'tutorials' expressions, but most seem to be trying to push a specific product. Here, what looks like a decent tutorial ... provided, it's written to use php, but otherwise it looks like a good primer: http://weblogtoolscollection.com/regex/regex.php
This seems to be a good regexp tool: http://gskinner.com/RegExr/
Akrikos May 25 '12 at 14:44 2012-05-25 14:44
source share