You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to have a variant of regex() that returns the MatchResult to be able to use capturing groups. For example, I have this in our project:
privatefun ParserState.match(pattern:Regex): MatchResult {
val result = pattern.matchAt(input, position)
?: fail("Expected pattern '$pattern', but there was no match.")
position += result.value.length
return result
}
This is handy in combination with map, or inline, using destructuring:
privateval date:Parser<LocalDate> = parser {
val (y, m, d) = match(Regex("""(\d{4})(\d{2})(\d{2})""")).destructured
LocalDate(
year = y.toInt().between(0..9999),
monthNumber = m.toInt().between(1..12),
dayOfMonth = d.toInt().between(1..31)
)
}
The text was updated successfully, but these errors were encountered:
It would be nice to have a variant of
regex()
that returns theMatchResult
to be able to use capturing groups. For example, I have this in our project:This is handy in combination with
map
, or inline, using destructuring:The text was updated successfully, but these errors were encountered: