Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: A Regex simple Question

by Sidhekin (Priest)
on Sep 06, 2007 at 15:54 UTC ( #637464=note: print w/replies, xml ) Need Help??


in reply to A Regex simple Question

Negative lookahead is always tricky ... you're on the right track though.

In this specific case you could do this:

/^a(?!b)(?:(?!ab).)+b$/

... or even this:

/^(?!.*ab)a.+b$/

... unless I've read you wrong, and you want to allow the string "ab" and even "ab000b"/"a000ab" (since the "ab" is not strictly between the "a" and the "b"), in which case you want this:

/^a(?:(?!ab.).)*b$/

... or even this:

/^(?!.+ab.)a.*b$/

Always tricky, the negative lookahead ... if you can split it, like FunkyMonk suggests (or some variation thereof), it'll be far more readable.

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://637464]
help
Chatterbox?
[Discipulus]: do you know the google like translation: a rich.. as a camel through the needle hole?
[choroba]: yes, I've read about it and its probable original form
[Discipulus]: Tomas in greek ~140Ad
[Discipulus]: also the 'today bred' was probably 'tomorrow's bred'
[LanX]: Novum Testamentum Graece
[erix]: "give us today our bread from tomorrow" -- that's not going to fly

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2017-11-23 20:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (338 votes). Check out past polls.

    Notices?