I have general question about regular expressions ...
# announcements
i
I have general question about regular expressions In Javascript we can do this
const matches = str.match(/[aei]/gi)
to check if string contains
a
,
e
or
i
character. However In kotlin this does not work. I wonder are the regular expression general cross-language concept or each language has own implementation (similar to other languages yet different)?
b
can't u use
matches
?
str.matches(Regex("/[aei]/gi"))
?
i
I can use it however it behaves differently then in js. Thats why I wonder - is the syntax that defines regular expression itself a cross-language standard?
d
Looks like there’s a standard but I don’t know how much it’s followed: https://en.wikipedia.org/wiki/Regular_expression#Standards. There’s a lot of similarities between regular expressions in different languages, but there are also some differences and certain features that some languages support that others don’t (ie. back referencing capture groups).
b
yeah the regex used in kotlin to make it work is different from that used with js
str.matches(Regex("[aei]"))
this works
g
Regexp implementation in Kotlin compatible with Java regexp
Same for js and Native