简体   繁体   English

将字符串与正则表达式匹配时出错

[英]error with matching a string with a regular expression

I am not sure what I did wrong, my regular expression below is fine:我不确定我做错了什么,下面的正则表达式很好:

var number = bio.match(\(?(?:\+62|62|0)(?:\d{2,3})?\)?[ .-]?\d{2,4}[ .-]?\d{2,4}[ .-]?\d{2,4});
console.log(number);

but I am getting the following error:但我收到以下错误:

SyntaxError: Invalid or unexpected token
?[90m    at Module._compile (internal/modules/cjs/loader.js:895:18)?[39m
?[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)?[39m
?[90m    at Module.load (internal/modules/cjs/loader.js:815:32)?[39m
?[90m    at Function.Module._load (internal/modules/cjs/loader.js:727:14)?[39m
?[90m    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)?[39m
?[90m    at internal/main/run_main_module.js:17:11?[39m

The correct one is:正确的是:

bio.match(\((?:\+62|62|0)?(?:\d{2,3})?\)?[ .-]?\d{2,4}[ .-]?\d{2,4}[ .-]?\d{2,4});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM