0

My Regular expression is :

/(url="\S+")/

And my string is

<code url="http://ns.adobe.com/textLayout/2008"><p>"test"</p></code>

I want replace this url value with an empty string.

str=str.replace(/(url="\S+")/, "");

but the output is coming like

<code </p></code>

I want the output like: <code ><p>"test"</p></code>

Can anyone tell me what's my mistake???

1 Answer 1

2

You should use str=str.replace(/(url="[^"]+")/, "");, it is safer.

See example.

The problem is with \S+ that means match any non-white space character [^\r\n\t\f ] as many times as possible (greedy) including < and >.

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

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.