I feel like there’s something in your question that isn’t clear. You say you can’t change the regexes, but you asked for a regex. On the surface, those two things sound mutually exclusive. Can you clarify what you do need?
Are you looking for ways to shoehorn that specific regex to match the first line of that string?
I can’t change those regular expressions because there are rought 8000 of them. What my code does is parse those XML files and create Crystal objects which are used to parse text.
What I want is a crystal Regex object that has the MULTILINE option but not the DOTALL option enabled, because that object behaves the way the parsers need it to behave.
For now I am running a hacked up crystal compiler, I’ll try to find a way to monkeypatch it, but if this option could exist in a future version, it would be nice ( I may propose a PR I guess :-) )
Well, couldn’t your parser rewrite the regex, so . is replaced by <something that matches anything but newline>? Does it need to use the exact same regex?
The odds of my code rewriting random subsets of the 8000 regexes and not breaking things is zero :-D
I have found workarounds to set the right flag combination, it’s just that Crystal’s refusal to set a number to 4 (MULTILINE) rather than 6 (MULTILINE | DOTALL) is a bit frustrating
I think it should be possible to enable the MULTILINE option alone without DOTALL. The current API doesn’t allow that though. The primary issue is that PCRE and PCRE2 use different values, so we cannot pass the flags directly and instead need some translation. This means it’s not possible to just use a custom value and we need to add explicit code for this.
As a minor invoncenience, we’re carrying legacy baggage in naming because CompileOptions::MULTILINE means MULTILINE | DOTALL.
So a constant for only MULTULINE needs to be called something like MULTILINE_ONLY.