To someone more experienced working with Regex pat...
# android
a
To someone more experienced working with Regex patterns. I have a regex pattern that I use to sanitise bad json responses from our backend, replacing empty objects (
{}
) with null, and empty lists (
[]
) with null. The pattern is as follows:
Copy code
Regex("""\{}|\[]""")
This compiles and works just fine in a unit test, but on android it crashes with:
Copy code
Caused by: java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 3
    \{}|\[]
       ^
        at java.util.regex.Pattern.compileImpl(Native Method)
        at java.util.regex.Pattern.compile(Pattern.java:1344)
        at java.util.regex.Pattern.<init>(Pattern.java:1328)
        at java.util.regex.Pattern.compile(Pattern.java:950)
        at kotlin.text.Regex.<init>(Regex.kt:89)
All I can surmise from this is that the underlying native implementation on Android is different.
r
post an example of the text you’re trying to find over?
a
Copy code
{ 
	"emptyObject" : {},
	"nonEmptyObject" : {
		"key" : "value"
	}
	"emptyList" : [],
	"nonEmptyList" : [
		"hello",
		"world"
	]
}
it fails when compiling the pattern, not when it processes the text
I've verified it works on standard JVM, but it's broken on Android
r
👍