Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Im not sure what this regex is called or how to write it

by moritz (Cardinal)
on Jul 28, 2011 at 13:54 UTC ( #917273=note: print w/replies, xml ) Need Help??


in reply to Im not sure what this regex is called or how to write it

scalar starts with "cat" but not ones followed anywhere with "dog".

Yes, a negative look-ahead:

use strict; use warnings; for (qw/cat dog catfoo catdog/) { print $_ =~ /^cat(?!dog)/ ? '[X]' : '[ ]', "$_\n"; } __END__ [X]cat [ ]dog [X]catfoo [ ]catdog
scalar starts with "cat" but not ones followed anywhere with "dog" except if its "dogs", or "dog" followed or preceeded by "collie".

If the "dog" is proceeded by "collie", then it's not "cat followed by dog" anymore, so we don't have to consider that case.

use strict; use warnings; for (qw/cat dog catfoo catdog catdogs catdogcollie/) { print $_ =~ /^cat(?!dog(?!s|collie))/ ? '[X]' : '[ ]', "$_\n"; } __END__ [X]cat [ ]dog [X]catfoo [ ]catdog [X]catdogs [X]catdogcollie

Replies are listed 'Best First'.
Re^2: Im not sure what this regex is called or how to write it
by misterperl (Beadle) on Apr 20, 2012 at 14:34 UTC
    Thank-You this was very helpful. Far moreso than *see the documentation* which of course could be an automated reply to ANY and ALL inquiries.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://917273]
help
Chatterbox?
[Corion]: I think I saw virtualsue more recently in person than online :-D
[virtualsue]: It's true that there was a bigger gap between the 2 yr old post and the one before it
[ambrus]: yes, I probably just didn't see you two years ago, because I'm not in perlmonks much
[virtualsue]: Nor am I :-)
[talexb]: virtualsue Heh .. long time no see! :)
[virtualsue]: I have a quiet Perl themed slack workspace
[virtualsue]: The person who talks to me on it the most *hates* Perl but she hates everything

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2017-09-26 13:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (295 votes). Check out past polls.

    Notices?