Skip to content

Instantly share code, notes, and snippets.

@afkvido
Last active February 28, 2023 21:16
Show Gist options
  • Save afkvido/70aa990330d51cc40587db8a9a36f6a9 to your computer and use it in GitHub Desktop.
Save afkvido/70aa990330d51cc40587db8a9a36f6a9 to your computer and use it in GitHub Desktop.
Capture one RegEx match from a String in Kotlin.
/** Captures a String from a regex */
fun String.match (regex : String) : String {
return this.match(Regex(regex))
}
/** Captures a String from a regex */
fun String.match (regex : Regex) : String {
val x : String? = regex.find(this)?.value
return if (x !== null) x else ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment