0

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.

1
  • You should approve one of the given answers as an "Accepted answer", if your problem got solved (by clicking on the check box outline to the left of the answer. This lets other people know that you have received a good answer to your question. ) Commented Dec 30, 2010 at 15:23

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

You need to create a regular expression object:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.