I need a little help with regular expressions. I need to locate a string:
{"users":[
and replace it with
{"name": "blaaaa", "users":[
In a complex json file.
I am completely ignorant about regexes.
Thank you
I need a little help with regular expressions. I need to locate a string:
{"users":[
and replace it with
{"name": "blaaaa", "users":[
In a complex json file.
I am completely ignorant about regexes.
Thank you
Using regex for JSON, or any other format that requires a parser, is not a good idea. Parse it using your favorite parser, add name
attribute, and serialize the results back to JSON.
If you would like to continue with a regex exercise, however, here is how you can do it: one simple approach is to search for the {
preceding "users"
, and then replace it with {"name":"blaaaa",
text. The "followed by" concept is expressed with the look-ahead construct (?=<text>)
:
{(?="users":\[)
Note the escape symbol \
in front of [
, which is necessary because [
is part of regex syntax.