Question

How would be the RegEx to make the string

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

become

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

?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top