简体   繁体   中英

Regexp javascript and replace

When I test my regex online (like http://regex101.com ), everything works fine. But when I test it in javascript, It doesn't. I don't understand what I'm doing wrong.

var input = 'fzef zef zef zef (,  ) dezdezfzef  ezf ze';
input = input.replace('/\(\,?\s{0,}?\)/g', '');
console.log(input);

Thank you

您需要删除正则表达式周围的引号:

input.replace(/\(\,?\s{0,}?\)/g, '')

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.

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