Aki
Aki

Reputation: 743

replacing dynamic string

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

Answers (1)

David Hedlund
David Hedlund

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

Related Questions