This regex shows a warning in IntelliJ: `Redundant...
# intellij
t
This regex shows a warning in IntelliJ:
Redundant character escape '\\]' in RegExp
However, if I remove it, browsers complain about invalid regex. Did I miss something?
Copy code
private val imageLinkRegex = "!\\[[^\\[]+\\]\\([^)]+\\)".toRegex()
k
IntelliJ seems correct. Paste your regex into regex101.com. Then in another tab, paste the same regex without escaping the "]". Compare the difference between the two tabs.
h
Regex implementations are different based on each platform, so I really recommend to test it on each platform and not blindly trust IntelliJ focussing on JVM.
r
Chrome 126.0.6478.127 accepts
const re = new RegExp("!\\[[^\\[]+]\\([^)]+\\)");
(i.e. no escape) for me
As does Firefox 126.0.1
a
There are two things to improve: • regex is different per KMP target, +1 this issue https://youtrack.jetbrains.com/issue/KT-49557/Different-dialects-of-regular-expressions-in-JS-and-other-platforms • IJ inspections only consider the Java regex engine. I don't know if there's a youtrack issue for this