Anyone knows why this is giving me a return value ...
# getting-started
c
Anyone knows why this is giving me a return value of false when it should be true?
"\b[01]+\b".toRegex().matches("11010011")
Basically what I’m trying to do is just check if there is something else besides 0 or 1 in the string. I tried also with
"/^[0-1]+$/".toRegex().matches("11010011")
But with the same result..
o
Remove the slash characters from your second pattern
s
Dont use
/
c
that was it.. thanks!
One question, why is it like this?
s
Modifiers are not given in the regex but as parameters to
toRegex()
so there is no need to use the
/
delimiters
o
Also any JetBrains IDE should warn you about this.
👍 1
c
Oh, didn’t noticed, and I was just trying stuff out in the kotlin playground instead of the IDE 😛
Thanks for your help!
m
If you hit
alt+Enter
on the string you get the “check” intention to test your expression in IntelliJ.