https://kotlinlang.org logo
Title
w

william

07/05/2019, 9:04 PM
im trying to match a json block with a regex (embedded in another document), and just the simple regular expression
Regex("{}")
shows up with the errors
Dangling metacharacter
on both the opening and closing bracket
{
or
}
don't have special meaning in regular expressions so im not so sure what the meaning is
s

Shawn

07/05/2019, 9:10 PM
Just remembered, they definitely do -
a{4,6}
for example matches
a
at least four and no more than six times
you’ll probably want to just escape them
w

william

07/05/2019, 9:16 PM
hm i guess in my case it doesnt have any meaning though, but yeah it seems like i had to do
\\{
only for the first curly bracket
woah so in pure kotlin you only need to escape the first one
but in android it crashes unless you escape both
k

Kroppeb

07/05/2019, 10:05 PM
well you need one to excape the
{
but because it's in a string literal I assume, you need to escape said
\
w

william

07/05/2019, 10:21 PM
yeah
im talking about the curly brackets though as in you need to escape both curly brackets only on android. in plain kotlin i can just escape the first one
k

Kroppeb

07/06/2019, 12:33 AM
I guess the the kotlin one has better error recovery or something
w

william

07/06/2019, 3:18 AM
the IDE tells me the second escape is unnecessary in both which is the odd part