Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: regex: negative lookahead

by Khen1950fx (Canon)
on Dec 05, 2011 at 20:50 UTC ( #941919=note: print w/ replies, xml ) Need Help??


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.

#! /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
I believe, if I"ve understood you correctly, that it works the way that it should. What do you think?


Comment on Re: regex: negative lookahead
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://941919]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2014-09-23 17:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (234 votes), past polls