Regex literal expressions


I’d like to request a regex literal feature.

val pattern2:Regex = /test-\d/i;

The main reason I feel it’s important is that without it, escaping gets unreadable quickly.


Are you aware of raw strings?

val r = Regex("""\d+""")

I never liked special strings for regex like in Perl.


Ah, thanks. For some reason I was thinking raw strings still used \ as an escape character. So the only thing you’d need to escape is the $. I think that’ll be fine.
I liked regex literals in AS3, I miss it :).


Note that escaping the $ in raw strings is done using



Compared to /\d+/ (in, e.g., Ruby) this is incredibly clunky.


$ usually last character in regexp and it does not need escaping in that position.


I’ve never liked / to delimit regex because regex often contain the similar \. But it is true Regex("""\d+""") is clunky compard to /\d+/. In my opinion """ looks not so good for short strings. Java’s new raw strings would look better here: Regex(`\d+`). Or all in one code block for better comparision: