@cr1901 in JS and TS regex literals look like this:
const r = /^[a-z0-9]+\s[0-9]+$/i;
which is identical to writing:
const r = new RegExp("^[a-z0-9]+\\s[0-9]+$", "i");
it's a separate thing to raw strings.
@cr1901 @gsuberland Specifically, in languages which support regex literals, these expressions *are not* free-text strings. The expressions can be checked as compile time, for example to ensure parens, brackets, and braces close properly.
Many such languages also have a more human-readable way to construct the expressions. For example, Swift’s Regex type supports writing an expression like this:
Capture(as: someInteger) { OneOrMore(.digit) }
It’s more verbose than “(?<someInteger>\d+)”, but complicated expressions get so much easier to understand.