CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: General Discussions: General Questions: Re: [iThunder] postive and negative lookahead assertions: Edit Log



Chris Charley
User

Nov 24, 2015, 12:15 PM


Views: 26305
Re: [iThunder] postive and negative lookahead assertions

I cannot comment on why your 2 regexs worked or, in the second case, failed to work. I am not well versed in regexs.

However if written as below, (in the posted program), both cases, (fox or not fox), function as desired.


Code
 
#!/usr/bin/perl
use strict;
use warnings;

my $re1 = '(?=.+fox)^line.+$';
my $re2 = '(?!.+fox)^line.+$';

for my $re ($re1, $re2) {
print "\tUsing regular expression $re\n";
while (<DATA>) {
print if /$re/;
}
seek DATA, 0, 0;
print "\n\n";
}

__DATA__
line1 brown fox
line2 black owl
line3 red dear



Output is:

Code
C:\Old_Data\perlp>perl test2.pl 
Using regular expression (?=.+fox)^line.+$
line1 brown fox


Using regular expression (?!.+fox)^line.+$
line2 black owl
line3 red dear



(This post was edited by Chris Charley on Nov 25, 2015, 9:20 AM)


Edit Log:
Post edited by Chris Charley (User) on Nov 24, 2015, 1:20 PM
Post edited by Chris Charley (User) on Nov 24, 2015, 4:29 PM
Post edited by Chris Charley (User) on Nov 24, 2015, 8:23 PM
Post edited by Chris Charley (User) on Nov 25, 2015, 3:39 AM
Post edited by Chris Charley (User) on Nov 25, 2015, 9:20 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives