Reputation: 1886
I've got an Excel document which uses regex. The expression is like this:
*<*>*
* is any array of symbols (including empty one). There are some matching strings examples:
abc<>abc
<abc>
<>
Can you help me with function in JS, which will return true, if the passed string is correct for this regex, otherwise it has to return false.
Upvotes: 1
Views: 66
Reputation: 670
Maybe this?
var str = 'some<blah>thing';
patt=/.*<.*>.*/g;
result=patt.test(str);
document.write("<br>Returned value: " + result);
Test it here: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_regexp_test
Upvotes: 1
Reputation: 145458
Assuming that set of any number of characters can be represented as .*
, then the right way is:
/^.*<.*>.*$/.test(str);
REF: https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions
Upvotes: 1