Problem with Replace in Eclipse
I'm using regex to match all non-quoted property names in my json files. Eclipse has no problem finding the desired matches, but when I want to replace the matched strings with "$2"
, I get this error: Match string has changed in file filename.json. Match skipped
Here's 开发者_开发技巧the regex I'm using:
((\w+)\s*(?!['"])(?=:))
Any idea on how to work around this issue?
It's a known bug: replace don't work when using a regex with a lookahead
It sounds like a problem with the tool rather than the regex, but I'm not familiar with Eclipse so I can't be more specific. Could it be expecting \2
instead of $2
?
Assuming the property names match \w+
, that regex should work fine, although the negative lookahead is redundant. If the next character is a colon--(?=:)
--then of course it isn't an apostrophe or quotation mark--(?!['"])
.
精彩评论