Reputation: 29
i need this in php to javascript.
echo preg_replace('/(\S)+\?/', '', 'http://example.com/?test=1');
THX
BTW: I tried
alert('http://example.com/?test=1'.replace('/(\S)+\?/g', ''));
but no happens.
Upvotes: 0
Views: 172
Reputation: 90012
You need to create a regular expression object:
alert('http://example.com/?test=1'.replace(/(\S)+\?/g, ''));
Upvotes: 2
Reputation: 1077
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.
Upvotes: 2