I know basic way to extract string matching a regex in scala:
val p = ".*(\\d+ minutes).*".r
val p(m) = "last 12 minutes."
I can get "12 minutes" in m.
But what if I want to match regex like \\d+ minute(s)?
. For example, I could get "12 minutes"
if input is "last 12 minutes."
, and "12 minute"
if input is "last 12 minute."
.
".*(\\d+ minute(s)?).*".r
doesn't work, maybe bracket is used to mark the matched regex we want, so more brackets appeared in regex doesn't work. And I know ".*(\\d+ minute[s]?).*".r
could satisfy my request, but what if I want to match \\d+ minutes( left)?
in which case I have to use bracket in the matched part?