The essence of the variable-width negative look-behind hack technique is that some part of a string that is needed in a subsequent match is matched and then "consumed" by (*SKIP) (which prevents backtracking) when the match is then forced to fail. (The \K operator already provides very nice variable-width positive look-behind.)
In the example below, the part that is "consumed" consists of some whitespace plus the entire 'Appl. Phys.' piece. If only a single whitespace character were guaranteed always to be present before 'Appl. Phys.' and this character was required for subsequent match, it would have been enough to consume only this character, but this seemed too fragile to me: more whitespace can easily creep in. Also, I have captured nothing because I don't understand just what you want from these captures: e.g., capturing the meta-quoted 'Appl. Phys.' is pointless because it's never going to change. What did you really want from these captures? (I'm also using non-capturing, atomic (?>pattern) groups here rather than simple non-capturing (?:pattern) groups because I think it makes reasoning about this trick a little easier.)
c:\@Work\Perl>perl -wMstrict -le
"use 5.010;
;;
my $j = quotemeta 'Appl. Phys.';
;;
LINE:
for my $l (
'R.N. Raox, J. Pure and Appl. Phys.',
'R.N. Raox, J. Pure & Appl. Phys.',
'R.N. Raox, J. Pure or Appl. Phys.',
'R.N. Raox, J. Pure and or Appl. Phys.',
'N.E. One, Fly Fishing and Appl. Phys.',
'N.E. One, Fly Fishing or Appl. Phys.',
) {
next LINE unless
$l =~ m{ (?> (?> and | &) \s+ $j (*SKIP)(*F))? \s+ $j }xms;
print qq{match: '$l'};
}
"
match: 'R.N. Raox, J. Pure or Appl. Phys.'
match: 'R.N. Raox, J. Pure and or Appl. Phys.'
match: 'N.E. One, Fly Fishing or Appl. Phys.'
Update: See the usual suspects: perlre (esp. Special Backtracking Control Verbs), perlretut, perlrequick.
Give a man a fish: <%-(-(-(-<
|