ruby regex not matching a string if "+" character in source -


i have string contains international phone number e.g. +44 9383 33333 bizzarely when attempt regex match (note regex correctly 'escaped') regex match fails

e.g.

 "001144 9383 33333".match(/(001144|004|0|\\+44)/) # works   "+44 9383 33333".match(/(001144|004|0|\\+44)/) # not work 

i've tried escaping input string e.g. +, \+ etc. etc no avail.

i must doing stupid here!?

you've got double backslash, telling regex parser literal backslash. since it's followed + regex parser looking 1 or more backslashes. try \+ (so whole thing should be: /(001144|004|0|\+44)/


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -