Reputation: 335
For some reason this regex keeps saying it is invalid in java, but on the online testers it works fine:
({.+?})
I am using it for a JSON data structure.
Is there a way to get it to work with Java?
Included link: http://regexr.com/3bs0p
Upvotes: 2
Views: 316
Reputation: 626748
Here are my 2 cents:
{
in Java regex to tell the engine it is not the brace starting the limiting quantifier. .group(0)
or $0
back-reference.The regex should look like
String pattern = "\\{.+?}"; // Note that `.+?` requires at least 1 character,
// Use .*? to allow 0 characters
And
Upvotes: 1
Reputation: 7232
You probably need to escape your { } with backslashes, since you are treating them as literal characters.
E.g.
(\\{.+?\\})
Upvotes: 1