<?xml version="1.0" encoding="windows-1252"?>
<node id="911397" title="Re^3: Using Look-ahead and Look-behind" created="2011-06-25 15:51:46" updated="2011-06-25 15:51:46">
<type id="11">
note</type>
<author id="634253">
AnomalousMonk</author>
<data>
<field name="doctext">
&lt;p&gt;
Here's a solution that exactly matches the phrases specified in AnonyMonk's [id://911357] post (which the code of [id://911361] does not &lt;i&gt;quite&lt;/I&gt; do), and also shows how to use the newfangled backtracking control verbs of 5.10 to emulate variable-width &lt;i&gt;negative&lt;/I&gt; look-behind. Variable-width &lt;i&gt;positive&lt;/I&gt; look-behind is emulated by 5.10's &lt;c&gt; \K &lt;/C&gt; assertion.
&lt;/P&gt;

&lt;p&gt;
Explanation:
&lt;ul&gt;

&lt;li&gt;
Any 'equity' that is preceded by
  &lt;ul&gt;
    &lt;li&gt; either a character that is not a comma or whitespace, or&lt;/LI&gt;
    &lt;li&gt; by the 'private' phrase &lt;/LI&gt;
  &lt;/UL&gt;
FAILS and is skipped over (this test has first precedence);
&lt;/LI&gt;

&lt;li&gt;
Otherwise, any 'equity' that is not followed by a comma that is then followed by any non-whitespace SUCCEEDS.
&lt;/LI&gt;

&lt;/UL&gt;
&lt;/P&gt;

&lt;c&gt;
&gt;perl -wMstrict -le
"use Test::More 'no_plan';
 ;;
 for my $ar_vector (
   [ YES =&gt; 'equity, private equity', ],
   [ YES =&gt; 'equity',                 ],
   [ no  =&gt; 'private equity',         ],
   [ YES =&gt; 'private equity,equity',  ],
   [ YES =&gt; 'private equity, equity', ],
   [ no  =&gt; 'equity,private equity',  ],
   [ no  =&gt; 'private equity',         ],
   [ no  =&gt; 'mutual funds',           ],
   [ no  =&gt; 'cds'                     ],
   ) {
   my ($expected, $string) = @$ar_vector;
   is match($string), $expected, qq{'$string'};
   }
 ;;
 sub match {
   my ($string) = @_;
   ;;
   my $char_not_comma_or_space = qr{ [^,\s]      }xms;
   my $private                 = qr{ private \s+ }xms;
   return 'YES' if $string =~
     m{ (?: $char_not_comma_or_space | $private) equity (*SKIP)(*FAIL)
        |
        equity (?! , \S)
      }xms;
   return 'no',
   }
"
ok 1 - 'equity, private equity'
ok 2 - 'equity'
ok 3 - 'private equity'
ok 4 - 'private equity,equity'
ok 5 - 'private equity, equity'
ok 6 - 'equity,private equity'
ok 7 - 'private equity'
ok 8 - 'mutual funds'
ok 9 - 'cds'
1..9
&lt;/C&gt;

</field>
<field name="root_node">
518444</field>
<field name="parent_node">
911361</field>
</data>
</node>
