开发者

JS: Regex in replace

i need this in php to javascript.

echo p开发者_StackOverflow中文版reg_replace('/(\S)+\?/', '', 'http://example.com/?test=1');

THX

BTW: I tried

alert('http://example.com/?test=1'.replace('/(\S)+\?/g', ''));

but no happens.


Remove quotes from your RegExp:

alert('http://example.com/?test=1'.replace(/(\S)+\?/g, ''));

If you have quotes there, then it's trying to replace the string '/(\S)+\?/g' with '', and therefore not doing regular expression replace.


You need to create a regular expression object:

alert('http://example.com/?test=1'.replace(/(\S)+\?/g, ''));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜