Javascript JS:Regex在replace中

Javascript JS:Regex在replace中,javascript,regex,replace,Javascript,Regex,Replace,我需要这在php到javascript echo preg_replace('/(\S)+\?/', '', 'http://example.com/?test=1'); THX 顺便说一句:我试过了 alert('http://example.com/?test=1'.replace('/(\S)+\?/g', '')); 但不会发生。从RegExp中删除引号: alert('http://example.com/?test=1'.replace(/(\S)+\?/g, '')); 如果

我需要这在php到javascript

echo preg_replace('/(\S)+\?/', '', 'http://example.com/?test=1');
THX

顺便说一句:我试过了

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

但不会发生。从RegExp中删除引号:

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

如果此处有引号,则它试图将字符串“/(\s)+\?/g”替换为“”,因此不执行正则表达式替换。

从RegExp中删除引号:

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

如果此处有引号,则它试图将字符串“/(\s)+\?/g”替换为“”,因此不执行正则表达式替换。

您需要创建正则表达式对象:

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

您需要创建正则表达式对象:

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

如果您的问题得到解决,您应该将其中一个给定答案批准为“接受答案”(通过单击答案左侧的复选框大纲。这会让其他人知道您收到了问题的正确答案)。如果您的问题得到解决,您应该将其中一个给定答案批准为“接受答案”(通过单击答案左侧的复选框大纲。这会让其他人知道您收到了问题的正确答案。)