Break it down into elements.
[^a-z]{3}
This says MATCH if you find 3 characters in a row which are not lowercase alphas. None of A-D match in this case because all of them have at least one lower-case alpha within those first 3 chars.
Add the negative lookahead:
(?![^a-z]{3})
Since NONE of them matched and we're doing a NEGATIVE lookahead then we end up with a positive and so all of A-D match here.
-Peter
_____
From: Arian Hojat - armyofda12mnkeys@gmail.com [mailto:+recoach+pbowers+7ef1bd310e.armyofda12mnkeys#gmail.com@spamgourmet.c om] Sent: Wednesday, May 21, 2008 4:32 PM To: General purpose mailing list for The Regex Coach Subject: Re: [regex-coach] negative lookahead assertion bug? message 9 of 20)
i think the last email was right about the pattern needing to be ([A-Z]-)(?![^a-z]{3})([a-z0-9A-Z]* ), this one is like a double NOT, almost right?
Now I'm just curious with a pattern like this.... This pattern ([A-Z]-)(?![^a-z]{3}) for text: A-xyz37 # B-ab6142 # C-Wxy66 # D-qrs93 matches A-xyz37 # B-ab6142 # C-Wxy66 # D-qrs93
Its looking to make sure the next thing after Capital Letter dash isnt 3 lower case letters, then 'nots' it? aka it really looks ahead for 3 lowercase letters, and i thought would only match A- and D-.
Thanks for the help btw, I wasnt sure if these were problems with program or just me understanding regexes bad :) which is most likely the case. Arian
2008/5/21 Laurent TAUPIAC ltaupiac@lfdj.com:
Negative lookup assertion should match to be validate. If "Wxy" not match, the positive assertion failed.
If you want a Capital letter followed by a dash but not followed by 3 lower case, you should match "not 3 lower case"
([A-Z]-)(?![^a-z]{3})([a-z0-9]* )
Regards
Arian Hojat a écrit :
Hello all,
had a question/possible bug report... For the example on this webpage: http://www.nuclearblender.com/leftovers/howto/regex/
this pattern is presented and i tried a positive lookup assertion which worked, but this first negative one only matched the first pattern (global option is on btw, so not sure why wont match). Pattern: ([A-Z]-)(?![a-z]{3})([a-z0-9]* ) Text to lookup: A-xyz37 # B-ab6142 # C-Wxy66 # D-qrs93
Should match B-ab6142 and C-Wxy66 as they both (have a capital letter followed by a dash), then (dont have 3 lower case letters), and (are following by letters/numbers and a space) only matches first one in the program.
Thanks, let me know if it should match only one if im wrong. Running latest version on Windows XP. Great Tool! Arian
_____
_______________________________________________
regex-coach site list
regex-coach@common-lisp.net
http://common-lisp.net/mailman/listinfo/regex-coach