I try to select a string based on regex, I use node.js ,here is my code :
var string = ' emaild@d.com Tel: +971000000000 0500000348';
var regExp = '\\(\\+971\\|00971\\|05\\)\\d\\{1,12\\}';
var find = string.match(regExp)[0];
console.log(find);
I need to select only numbers that starts with +971 , 00971, 05 , this returns null, (I had to escape twice coz it throws an error if I don't) this regex works fine: '\\\\+971\\\\d{1,12}';
(\+971|00971|05)(\d{1,12})
Get group 2 and you should get what you want. I am not sure why you need to escape also. It is working for me without escaping.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.