I have something similar to the following code in my Android app,
val regex = Regex("\\$\\{}")
It works well for the unit tests in src/test, but it throws PatternSyntaxException for the unit tests in src/androidTest, and when I run the whole app, it has the same exception.
Here is the exception details
java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 5
\$\{}
^
at com.android.icu.util.regex.PatternNative.compileImpl(Native Method)
at com.android.icu.util.regex.PatternNative.<init>(PatternNative.java:39)
at com.android.icu.util.regex.PatternNative.create(PatternNative.java:35)
at java.util.regex.Pattern.compile(Pattern.java:1426)
at java.util.regex.Pattern.<init>(Pattern.java:1401)
at java.util.regex.Pattern.compile(Pattern.java:959)
at kotlin.text.Regex.<init>(Regex.kt:89)
I have to write this way to make it work in Android Environment.
val regex = Regex("\\$\\{\\}")
But android studio will complain about this

Anyone knows why this happens?