in reply to Another Look behind

UPDATE: See AnomalousMonk's reply below. My bad for misreading OP's problem. </UPDATE>

A clear explanation of where the word "text" originates in Lines 007 and 010 would be helpful.

But your chief problems are miscounting the captures and the failure of your regex to account for the space between "and" or &amp; and the journal name. Here's a less-overly-complicated version:

#!/usr/bin/perl use 5.018; my $RLine = "R.N. Raox, J. Pure and Appl. Phys."; my $Jrnl = qr/Appl. Phys./; if( $RLine =~ /(.+)( and | &amp; )($Jrnl)$/ ) { #NB trailing space bef +ore the journal name print "11: $1\n"; print "33: $3\n"; print "Matched\n"; } else { print "Not Matched\n"; }
Output:
11: R.N. Raox, J. Pure 33: Appl. Phys. Matched

Update: pasted wrong version of comment at Ln 008. Fixed.

Replies are listed 'Best First'.
Re^2: Another Look behind
by AnomalousMonk (Archbishop) on Mar 12, 2015 at 19:15 UTC

    Some thoughts:

    • The regex you give matches against "R.N. Raox, J. Pure and Appl. Phys.", but I thought dominic01's OP wanted no match in this case because ' Appl. Phys.' is preceded by 'and';
    • The regex defined by  my $Jrnl = qr/Appl. Phys./; will also match something like 'Applx Physy';
    • You have the  use 5.018; statement at the beginning of your code, but nothing in the code seems to require version 5.18+.


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