Question

How would be the RegEx to make the string

'{"a":"st", "b":"EvalMe(nd)", "c":"th"}'

become

'{"a":"st", "b":nd, "c":"th"}'

?

Était-ce utile?

La solution

A simple find and replace is all you need
find: /"EvalMe\(([^()]*)\)"/
replace: \1 or $1

Autres conseils

It looks like json. So first using json library(not sure how in Javascript) parse this value first "b":"EvalMe(nd)" from the json.

Then from there do a regex replace like below way and then update your json.

output = "EvalMe(nd)".replace(/.*\((.*?)\).*/, "$1");
                                   ^^^^^ picking of nd is here

Here using regex it is capturing the nd in group $1 and replace everything with empty, and keeping the group.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top