Eva
Eva

Reputation: 109

regex to replace values

Input:

.city.playground[?(@.playhouse == 'true' && @.IsPoolAvailable=='true')].checked]

Output:

.city.poolavailable.checked

Regex to convert input to output:

result = result.replace("playground[?(@.playhouse == 'true' && @.IsPoolAvailable=='true')]",'poolavailable');

This regex does not render the expected output. Please help with any other regex that can be used.

Upvotes: 1

Views: 149

Answers (3)

Mr.lin
Mr.lin

Reputation: 99

you can use the capture group to solve it.As follow:

result.replace(/(\.city\.).*?(\.checked)\]/i,'$1poolavailable$2');
click here to look at

Upvotes: 0

CinCout
CinCout

Reputation: 9619

You need to escape the special characters in your regex. Use:

playground\[\?\(@\.playhouse\s*==\s*'true'\s+&&\s+@\.IsPoolAvailable\s*==\s*'true'\)\](\.\S+)\]

Then replace the match with poolavailable$1.

result = result.replace("playground\[\?\(@\.playhouse\s*==\s*'true'\s+&&\s+@\.IsPoolAvailable\s*==\s*'true'\)\](\.\S+)\]", "poolavailable$1");

Demo

Upvotes: 1

Oliver Hao
Oliver Hao

Reputation: 735

You can try this regular expression:playground\[\?\( @\.IsPoolAvailable=='true'\)\]

Upvotes: 0

Related Questions