how do I extract substring (group) using regex without knowing if regex matches?

Viewed 18048

I want to use this

val r = """^myprefix:(.*)""".r
val r(suffix) = line
println(suffix)

But it gives an error when the string doesn't match. How do I use a similar construct where matching is optional?

Edit: To make it clear, I need the group (.*)

3 Answers
Related