Skip to main content


Some have said that I am capable of writing #perl in any language. Behold my #Ruby. #programming #regex
This entry was edited (1 year ago)
in reply to Füsilier Breitlinger

It does, but I don't want to ignore it, since I'm recreating the same whitespace via the match groups. /m let's me do multi-line match while preserving indentations after the fact.
This entry was edited (1 year ago)
in reply to Scott Williams 🐧

/x has nothing to do with matching whitespace. It's for letting you write your regexes in a more readable way by formatting them sensibly (using multiple lines, indentation, etc).

(/m has little to do with multiline; it just changes what ^ and $ mean.)

in reply to Füsilier Breitlinger

/m has everything to do with multiline. /x is literally "ignore whitespace"

docs.ruby-lang.org/en/3.2/Rege…

Lastly, I don't care, because this script works as I intended it to 😀 .

This entry was edited (1 year ago)
in reply to Scott Williams 🐧

Oh, interesting. That's very different from Perl/JavaScript then, which uses /s (confusingly referred to as "single line" mode sometimes) to make . match newlines.

The main point, however, is that /x ignores whitespace in the regex, not in the string it is matching against. That is, instead of /(?<test1>.*stage\(.Test.\)\s+\{[^}]+\})/, you can write /(?<test1> .* stage\( . Test . \) \s+ \{ [^}]+ \} )/x or even:

/ (?<test1><br>    .*<br>    stage\( . Test . \)<br>    \s+<br>    \{ [^}]+ \}  # a block in curly braces<br>  )<br>/x<br>

And it all does the same thing since /x mode effectively strips whitespace/comments from the regex before matching.
This entry was edited (1 year ago)
in reply to Füsilier Breitlinger

Yup, \m is more equivalent to Python's re.DOTALL. /m is MULTILINE where /x is EXTENDED mode.

Also, yes, it's a different parser than Javascript and Perl. It's based on oniguruma instead of PCRE. Note that the negations and matchers aren't PCRE compliant either.

The \s+ I used for whitespace works the same in /x mode.

docs.ruby-lang.org/en/3.2/Rege…

This entry was edited (1 year ago)
in reply to Scott Williams 🐧

vulgar language

@Perl I’m glad mastodon.online/@vwbusguy/1112… works for you, but I feel pity for when you come back to it later.

It’s nothing to do with #Perl and everything to do with shitty #regex possible in almost any #programming language.

Though it’s true that Perl’s reputation took a lot of damage from shitty developers filling the world with shitty #regexes in their shitty Perl code. So you’re in a big group, albeit via #Ruby.


Some have said that I am capable of writing #perl in any language. Behold my #Ruby. #programming #regex

Perl reshared this.