我有一个JSON字符串,它是:

{"dependencies":["xz","pkg-config","glib","gobject-introspection"],"conflicts_with":[],"caveats":null,"options":[{"option":"--universal","description":"Build a universal binary"}]}

我写了一个正则表达式来查找“dependencies”后面的数组:
(?<=\"dependencies\":).*[^:](?=,)

在Java中:
"(?<=\\\"dependencies\\\":).*[^:](?=,)"

但是结果却是:
["xz","pkg-config","glib","gobject-introspection"],"conflicts_with":[],"caveats":null,"options":[{"option":"--universal"

并且只有最后一个冒号被排除在外。

请帮帮我。

最佳答案

我建议使用此正则表达式:

(?<=\"dependencies\":).[^:]*(?=,)

或者,几乎相等:
(?<=\"dependencies\":)[^:]+(?=,)

关于java - 正则表达式Negate Colon不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29513945/

10-11 22:03