How would be the RegEx to make the string

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

become

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

?

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top