0

For those guys who are experienced in regExps in kotlin I have a question.

I need to find all words in curly bracers inside String. Let's say we have next string:

"{user} changed an issue from {fromStatus} to {toStatus}"

I'm using this regular expression:

\{+(\w)+}

I tried to use different sites to test my regExp, and it works good, I even wrote a JUnit test to make sure that everything is ok. But when I start application, I see next message:

java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 9:
\{+(\w)+}
         ^
at java.util.regex.Pattern.compileImpl(Native Method)
at java.util.regex.Pattern.compile(Pattern.java:411)
at java.util.regex.Pattern.<init>(Pattern.java:394)
at java.util.regex.Pattern.compile(Pattern.java:381)
at kotlin.text.Regex.<init>(Regex.kt:89)

Here's my code:

private fun initTemplate() {
    """\{+(\w)+}""".toRegex()
            .findAll(TEST_STRING)
            .forEach {
               //some action
            }
}

Any suggestions, how to fix this problem? Could you tell me where's my mistake?

Thanks in advance

hornet2319
  • 379
  • 3
  • 15

0 Answers0