Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: A Regex simple Question

by johngg (Canon)
on Sep 06, 2007 at 15:55 UTC ( [id://637466]=note: print w/replies, xml ) Need Help??


in reply to A Regex simple Question

A negative look-ahead is fine, just move the .* into the assertion.

if ($s =~ /^a(?!.*ab).*b$/) {

Cheers,

JohnGG

Update: If you want "a00000000ab" to match then you could change the look-ahead to ensure there is at least one character after the "ab".

use strict; use warnings; my @strings = qw{ a000000000b a0a0000b00b a0000ab000b a00000000ab }; print m{^a(?!.*ab.).*b$} ? qq{$_: matched\n} : qq{$_: unmatched\n} for @strings;

which produces

a000000000b: matched a0a0000b00b: matched a0000ab000b: unmatched a00000000ab: matched

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found