Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Multiline replace regexp.

by hippo (Bishop)
on May 21, 2018 at 13:05 UTC ( [id://1214974]=note: print w/replies, xml ) Need Help??


in reply to Multiline replace regexp.

$q =~ s/^.*$a//sm;

The "m" is for multiline, which is a handy mnemonic.

Update: Although, as discussed in this thread the "m" is not actually required if we understand what nikolay wants correctly. We can golf the whole thing down to:

$q =~ s/.*$a//s;

as here:

#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 1; my $q = 'qqqweqwe asdasdasd zxczxczxc tyutyutyi '; my $a = 'zxczxczxc'; my $want = "\ntyutyutyi\n"; $q =~ s/.*$a//s; is ($q, $want, "With /s only and no anchor - matched");

Replies are listed 'Best First'.
Re^2: Multiline replace regexp.
by LanX (Saint) on May 21, 2018 at 13:10 UTC
    Are the effects of /s really wanted here?

    update

    I'm confused, depending on how I understand the OP it's either /s or /m , but not both.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Wikisyntax for the Monastery

      Are the effects of /s really wanted here?

      Yes, because without /s the newlines are not matched.

      Code added for clarity:
      #!/usr/bin/env perl use strict; use warnings; use Test::More tests => 2; my $q = 'qqqweqwe asdasdasd zxczxczxc tyutyutyi '; my $a = 'zxczxczxc'; my $want = "\ntyutyutyi\n"; my $t = $q; $t =~ s/^.*$a//sm; is ($t, $want, "With /s - matched"); $t = $q; $t =~ s/^.*$a//m; isnt ($t, $want, "No /s - not matched");
        If that's what the OP wants, then better omit /m

        Otherwise is ^ matching for every line start, not only the strings start.

        It's at best redundant.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1214974]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-26 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found