@matches = ( $filestr =~ /^[0-9]+\. (.+\n)*/mg );
I have a file that's been read into filestr, yet for some reason the above regex, which should match the beginning of a line, followed by a number, a dot, a space, and then any number of lines followed by a newline (thus ending when there is a line with only a newline on it), seems to just produce some single lines from the file.
When I do something like
@matches = ( $filestr =~ /^[0-9]+\. .+\n/mg );
I correctly match a single line.
When I do this
@matches = ( $filestr =~ /^[0-9]+\. .+\n.+\n/mg );
I match the same single lines, followed by some seemingly unrelated line. What's wrong with my regex?
Note: The regex works fine in this regex tester:https://regex101.com/, it just won't work in perl.
Example, in this text:
1. This should
match
2. This should too
3. This
one
also
the regex should match
1. This should
match
and
2. This should too
and
3. This
one
also
\Rinstead of\n. However, here you'd better change the whole approach and read line by line checking each subsequent one./^[0-9]+\..*?(?:\R{2}|\z)/gsm