I have a Scala regex which does match with pattern.findFirstMatchIn()
but not with a match ... case
unpacking statement:
val pattern = "\"(\\d+?)\",\"(.*?)\",(.+)$".r
val line = "\"1795\",\"title\",\"desc"
println(pattern.findFirstMatchIn(line).isDefined)
val pattern2Unpacking = line match {
case pattern( category_id, title, description) =>
true
case _ => false
}
println(pattern2Unpacking)
The line to match is "1795","title","desc
and the lack of a trailing quote is intentional.
Output is true
and false
rather than both true
.
I have looked at this answer and this but I cannot relate the solutions to my problem. Omitting the boundary matchers does not change anything.
What is going wrong here?
Update following comments
Spoiler: Part of the apparent weirdness reported in the following is explained by the fact that my data contains characters not displayed by IDE, which is something to watch out for in these situations. For an excellent in-depth explanation what is actually happening, see the accepted answer.
Here is a screenshot from my IntelliJ. Code on top is copy paste from the link by @WiktorStribiżew. Code on the bottom is the one I based this post on. Output window is included in the screenshot. This is not a prank, and I find this a little scary.
Update 2
This is even better: http://ideone.com/KsIIc1
No, I neither fake screenshots nor did I hack ideone.com to play a prank.