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.
/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.)
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.
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.
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.
Füsilier Breitlinger
in reply to Scott Williams 🐧 • • •/x
flag?Scott Williams 🐧
in reply to Füsilier Breitlinger • • •Füsilier Breitlinger
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.)Scott Williams 🐧
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 😀 .
class Regexp - Documentation for Ruby 3.2
docs.ruby-lang.orgFüsilier Breitlinger
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:And it all does the same thing since
/x
mode effectively strips whitespace/comments from the regex before matching.Scott Williams 🐧
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…
class Regexp - Documentation for Ruby 3.2
docs.ruby-lang.orgMark Gardner
in reply to Scott Williams 🐧 • • •@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.
Scott Williams 🐧
2023-10-10 20:05:37
Perl reshared this.