here is my code:
object test extends App {
private val PLAYER_REGEX = """[\s\S]*(?:<td class="align-middle plus-size"> <s class="text-muted">|<td class="align-middle plus-size">)(.*)(?:</s> </td></tr>|</td></tr>)""".r
val str ="""<td class="align-middle plus-size"> <s class="text-muted">first</s> </td></tr>"""
val str2 ="""<td class="align-middle plus-size">second</td></tr>"""
private def find(str:String) = {
PLAYER_REGEX.findFirstMatchIn(str) match {
case Some(data) => data.group(1).trim
case None => "Not found"
}
}
println(find(str))
println(find(str2))
}
And Output is
first</s>
second
My question is - why those redundant
</s>
in first case? I thought that
(?:</s> </td></tr>|</td></tr>)
should select first occurence
</s> </td></tr>
but looks like it select
</td></tr>???
Off course I can trim it, but it looks ugly. If you can provide another regex I'll also will be glad:)