Skip to content

Instantly share code, notes, and snippets.

@PaulWoitaschek
Created February 23, 2022 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulWoitaschek/d3c84e0ae8e91cf9ceebb05286bd9fbe to your computer and use it in GitHub Desktop.
Save PaulWoitaschek/d3c84e0ae8e91cf9ceebb05286bd9fbe to your computer and use it in GitHub Desktop.
package voice.bookOverview.views
import voice.bookOverview.views.RegexType.Email
enum class RegexType(
// language=RegExp
internal val regex: String
) {
Email(".*?"),
Name("(.*)")
}
private val regexCache = mutableMapOf<RegexType, Regex>()
operator fun Regex.Companion.get(type: RegexType): Regex {
return regexCache.getOrPut(type) {
type.regex.toRegex()
}
}
fun main() {
Regex[Email].findAll("mail@sth.de")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment