Huy Vo Huy Vo - 2 months ago 15
Scala Question

How to match a string containing double quotes?

I want to match a string containing double quotes like this "ABC"DEF"" using Scala regex. Here's my pattern:

val pattern = "\"[^\"]*\"".r


The fact is I want to match some LOLCODE string (it doesn't use
\"
to present a quote inside a string, it use
:"
instead).

Please help me!

Answer

Does this work:

val pattern = "\"((:\")|([^\"]))*\"".r

(I haven't tested it)