Reputation: 165
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???
Upvotes: 0
Views: 280
Reputation: 626758
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 >
.
Upvotes: 2