views:

116

answers:

2

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?

+1  A: 

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--(?!['"]).

Alan Moore
Eclipse does uses $1, $2, not \1, \2. Thanks for improving the regex, BTW.
Imran
+3  A: 

It's a known bug: replace don't work when using a regex with a lookahead

cement
So it *was* the tool. Thanks for clearing that up.
Alan Moore