i'm probably doing something very dumb here (tryin...
# announcements
j
i'm probably doing something very dumb here (trying to match a literal dollar followed by chars in a string)...
Copy code
println("Hello \$name".contains(Regex("[a-zA-Z0-9]+"))) // true
println("Hello \$name".contains(Regex("\$[a-zA-Z0-9]+"))) // false
have to escape the dollar in the string literal or Kotlin will treat it as a reference and have to escape the dollar in the pattern or that means end of string
s
What you use
\\$
or
[$]
instead of
\$
?
👍 1
j
ah both of those work fine. thanks
n
even better: use
Regex("""\$\w+""")
because you don't have to double the
\
in raw string lterals