in reply to Re: Regex bug? matching multiple newline with /m
in thread Regex bug? matching multiple newline with /m

Ha, yes bitten by interpolation. Thanks.

Now I'm wondering how many times in the past I've had difficulties with a multiline regex and it was due to the incorrect assumption that it would consume the \n...

  • Comment on Re^2: Regex bug? matching multiple newline with /m

Replies are listed 'Best First'.
Re^3: Regex bug? matching multiple newline with /m
by AnomalousMonk (Archbishop) on Aug 09, 2021 at 14:51 UTC
    ... bitten by interpolation.

    Perhaps better to say "bitten by failure to enable strict" (and I would also recommend warnings).


    Give a man a fish:  <%-{-{-{-<

Re^3: Regex bug? matching multiple newline with /m
by BillKSmith (Monsignor) on Aug 14, 2021 at 15:23 UTC
    The problem with interpolation is covered in the documentation for  /PATTERN/msixpodualngc in Regexp Quote Like Operators.
    If "'" is used as the delimiter, no variable interpolation is done.

    This is not enough to solve your problem with the newline because $ is a zero width assertion. Assertions

    Besides "^" and "$", Perl defines the following zero-width assertions:

    In this case, it is probably best to match the newline explicitly and not use the anchor at all.

    Bill