Reputation: 743
I need JavaScript code for replacing a substring of given string.
I have a variable say:
var c="<name='abc'&id='123'/>";
I need to replace the name='abc' with name='def'. 'abc' is a dynamic value so the replace function must do a match and replace.
End result required:
<name='def'&id='123'/>
Can you give me an example how to do this?
Upvotes: 0
Views: 114
Reputation: 129832
Something like this:
c = c.replace(/name='[^']+'/, "name='def'");
It's hard to tell from your question exactly what you're after...
Upvotes: 1