What @jling is saying is you need escaping, and note you could have done it this way
but note also, instead of needing escaping (for regular strings) you can use the raw type, like
That gives you a string, not a Regex, so you would still need Regex(raw"^\s*text") to make it so. That can help if you would otherwise need lots of escaping.
This got me thinking (since the r and raw strings are implemented by macros, r_str and raw_str), can you do macro composition (or here for string-types, so indirectly)?
r∘raw"^\s*text" doesn’t work (and maybe it shouldn’t…), nor does
(r∘raw)"^\s*text". I’m ok with not having the option, since it’s likely very rare to do…
but it got me thinking, should this have been the default for Julia’s regexes, or at least also be provided?
A r_raw type of regex/string (or rather name it raw_r?) could be made. I’m a bit stumped how. The former is implemented like:
macro r_str(pattern, flags...) Regex(pattern, flags...) end
and raw by:
macro raw_str(s); s; end
Note, PCRE is the regex engine (from Perl) library used in Julia, so the error comes from it, since something wrong with your regex, seemingly this (since Julia is 1-based, should mean the same as “offset 0” there)::
I didn’t read carefully, but it seems your fix may be as simple as
r"^[[:space:]]*text" in a sense needing a type of intentional “escaping”, if you will).