<?xml version="1.0" encoding="windows-1252"?>
<node id="941919" title="Re: regex: negative lookahead" created="2011-12-05 15:50:14" updated="2011-12-05 15:50:14">
<type id="11">
note</type>
<author id="528646">
Khen1950fx</author>
<data>
<field name="doctext">
I've never had a the need to use a lookaround, but your question piqued my curiosity. As an experiment, I used
[href://http://search.cpan.org/~dland/Regexp-Assemble-0.35/Assemble.pm|
Regexp::Assemble] to rework your example because it just does the right thing with assertions, lookaheads, and lookbehinds.
&lt;c&gt;
#! /usr/bin/perl -slw

use strict;
use Regexp::Assemble;

my $needs = Regexp::Assemble-&gt;new-&gt;add( qw[ FILE INFO ] );
my $has   = Regexp::Assemble-&gt;new-&gt;add( qw[ FILE INFO SYSLOG ] );

while( defined( $_ = &lt;DATA&gt; )) {
    chomp;
    if( /($needs)/ ) {
        print $needs-&gt;as_string;
    }
}
while( defined( $_ = &lt;DATA&gt; )) {
    chomp;
    if( /($has)/ ) {
        print $has-&gt;as_string
    }
}

__DATA__
FILE
INFO
SYSLOG
&lt;/c&gt;
I believe, if I"ve understood you correctly, that it works
the way that it should. What do you think?




</field>
<field name="root_node">
941881</field>
<field name="parent_node">
941881</field>
</data>
</node>
