Regular Expression Doesn't Work Correctly In Javascript?
Solution 1:
I corrected your javascript code and got the following:
Personally I think the matching (group) problems are related to http://regex101.com/. Your expression works definitly in JavaScript (see the fiddle) and in Java (with escaping corrections). I minimalized your JavaScript slightly and used the pgn data from a parameter not a text input.
I am not aware that
=~
is available in JavaScript, but maybe I am wrong. Using JavaScript you loop through the matches using something like: (Why does it not format like code???)pattern=/myregexp/; while ((match=pattern.exec(mytext))!=null) { //do something }
If no match is found for a group it returns
null
. You adress the groups by using thematch
variable from above with an index likematch[2]
is matching group 2.
Post a Comment for "Regular Expression Doesn't Work Correctly In Javascript?"