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 & and the journal name. Here's a less-overly-complicated version:
Output:#!/usr/bin/perl use 5.018; my $RLine = "R.N. Raox, J. Pure and Appl. Phys."; my $Jrnl = qr/Appl. Phys./; if( $RLine =~ /(.+)( and | & )($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"; }
11: R.N. Raox, J. Pure 33: Appl. Phys. Matched
Update: pasted wrong version of comment at Ln 008. Fixed.
In reply to Re: Another Look behind
by ww
in thread Another Look behind
by dominic01
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |