I have a JSON String which is:
{"dependencies":["xz","pkg-config","glib","gobject-introspection"],"conflicts_with":[],"caveats":null,"options":[{"option":"--universal","description":"Build a universal binary"}]}
And I wrote a regular expression to find the array behind "dependencies":
(?<=\"dependencies\":).*[^:](?=,)
in Java:
"(?<=\\\"dependencies\\\":).*[^:](?=,)"
However the result turns out:
["xz","pkg-config","glib","gobject-introspection"],"conflicts_with":[],"caveats":null,"options":[{"option":"--universal"
And only the last colon was excluded.
Please help me out.
I suggest using this regex:
(?<=\"dependencies\":).[^:]*(?=,)
Or, almost equal:
(?<=\"dependencies\":)[^:]+(?=,)
You could use a non-greedy zero-or-more quantifier:
(?<=\"dependencies\":)\[(.*?)\]
This would match ["xz","pkg-config","glib","gobject-introspection"] in the provided JSON.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With