in reply to regex: negative lookahead
I've never had a the need to use a lookaround, but your question piqued my curiosity. As an experiment, I used
Regexp::Assemble to rework your example because it just does the right thing with assertions, lookaheads, and lookbehinds.
I believe, if I"ve understood you correctly, that it works the way that it should. What do you think?#! /usr/bin/perl -slw use strict; use Regexp::Assemble; my $needs = Regexp::Assemble->new->add( qw[ FILE INFO ] ); my $has = Regexp::Assemble->new->add( qw[ FILE INFO SYSLOG ] ); while( defined( $_ = <DATA> )) { chomp; if( /($needs)/ ) { print $needs->as_string; } } while( defined( $_ = <DATA> )) { chomp; if( /($has)/ ) { print $has->as_string } } __DATA__ FILE INFO SYSLOG
|
---|
In Section
Seekers of Perl Wisdom