https://kotlinlang.org logo
#getting-started
Title
# getting-started
r

Richard Gomez

11/10/2021, 8:49 PM
Is there any documentation that clearly explains the difference between Kotlin's
Regex
vs. Java's
Pattern
?
v

Vampire

11/10/2021, 9:05 PM
You mean regarding the regex syntax?
c

Casey Brooks

11/10/2021, 9:05 PM
Kotlin's
Regex
class is essentially a multiplatform wrapper around each platform's standard Regex implementation. As such, the specific pattern format may be slightly different between different targets, but on JVM,
Regex
delegates to
java.util.regex.Pattern
. So the only difference between
Regex
and
Pattern
is the actual Kotlin API, not the pattern syntax itself https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-regex/
e

ephemient

11/10/2021, 9:07 PM
as the link says, Kotlin Regex syntax is Java Pattern on JVM, JS RegExp on JS, and I'm not sure what on native (it's not documented)
d

Dominaezzz

11/10/2021, 9:07 PM
Native was implemented from scratch to match JVM iirc.
e

ephemient

11/10/2021, 9:11 PM
I see harmony_regex tests in the kotlin.git/kotlin-native so that checks out
would be nice if the documentation said anything about it though… my default assumption for native languages is PCRE unless otherwise specified
☝️ 2
c

Casey Brooks

11/10/2021, 9:15 PM
yeah, PCRE would have been my guess too
Doesn't count as docs I guess
😂 1
r

Richard Gomez

11/10/2021, 9:52 PM
Thanks @Casey Brooks: I was aware that Regex (on JVM) used the Java Pattern syntax, but it wasn't clear from the text that Regex = Pattern.
Represents a compiled regular expression. Provides functions to match strings in text with a pattern, replace the found occurrences and split text around matches.
For pattern syntax reference see Pattern.
3 Views