I have a list with string and want to sort any string that matches the following pattern:
a+[0-9]+framewall+[0-9]+
开发者_如何学CI.e., the string would be something like a3framewall21.
What is the easiest way of doing this in Javascript?
Thanks,
Have you tried the string.match method?
js> mystring='a3framewall21';
a3framewall21
js> mystring.match(/a\d+framewall\d+/);
a3framewall21
/a\d+framewall\d+/.test(str);
– cwolves 8 mins ago
This is superior because it returns a boolean value. So you can write for example:
function doesItMatch(regex, query) {
return regex.test(query);
}
Which will allow you to write things like this (which string.match(...) cannot do because the values are truthy and falsy):
doesItMatch(regex1,query)==doesItMatch(regex2,query)
精彩评论