I can't understand why this simple regex doesn't match anything. It always fails and throws exception:
val match = Regex("""\d+""").matchEntire("A123B")?: throw Exception("Regex fail")
You want to match an entire input with matchEntire and a \d+ pattern:
fun matchEntire(input: CharSequence): MatchResult? (source)
Attempts to match the entire input CharSequence against the pattern.
Return An instance of MatchResult if the entire input matches or null otherwise.
However, A123B does not only consist of digits. If you need to find a partial match, use find.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With