Reputation: 70
I have a random variable lets call it R inside a curly brackets like so:
{R}
I have tried to regex it with this:
{(.*?)//}
I then have this error
"Caused by: java.util.regex.PatternSyntaxException:
Syntax error U_REGEX_RULE_SYNTAX near index 1:"
Indicator targeting {(.*?)} "("
I tried doing it without the brackets same error. This time indicator targets "."
Could someone help me find an alternate solution to regex items inside a curly brackets?
Upvotes: 1
Views: 1956
Reputation: 30273
You can escape special characters using a backslash \
. See What special characters must be escaped in regular expressions? for more information (although there is no general rule). Try escaping the curly braces {}
and slashes //
.
Upvotes: 0
Reputation: 29595
Escape the {}s:
String regStr = "\\{.\\}";
I've found this interactive regex testing page useful in refining Java regular expressions.
Upvotes: 1
Reputation: 5605
Curly brackets are used in regexp to define specific sequence repetition.
you have to escape them in the regexp.
\{(.*?)\}
should work better
Upvotes: 3
Reputation: 15434
Try escaping curly braces:
String regex = "\\{(.*?)\\}";
Upvotes: 5