Cha*_*hty 1 javascript regex replace parentheses
var s = "1236(75)";
var s = s.replace(/\(|\)/g, '');
alert (s); // this gives me 123675
what i actually need is 75
any help will be appreciated!
Run Code Online (Sandbox Code Playgroud)
上面的代码结果是123675,但我需要它才能返回75,请帮忙
使用^.+从输入字符串的开头相匹配的一切.
var s = "1236(75)";
var s = s.replace(/^.*\(|\)/g, '');
Run Code Online (Sandbox Code Playgroud)
这就是说,你可以使用正则表达式做相反:不是摆脱你的一切不想要的,只是你相匹配的零件也希望:
var match = s.match(/\((\d+)|\)/)[1];
Run Code Online (Sandbox Code Playgroud)