-
-
Save PaulWoitaschek/d3c84e0ae8e91cf9ceebb05286bd9fbe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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