This is the P2PU Archive. If you want the current site, go to www.p2pu.org!

Python Challenges

My recent threads

You haven't posted any discussions yet.

Recently updated threads

Hints: 3

Go back to: General discussion

Here is my pattern: '[A-Z]{3}[a-z][A-Z]{3}'
I'm not entirely sure that it matches ONLY three on each side, can someone confirm or point me in the right place? My source seems to say so.

jroturie's picture
jroturie
Tue, 2011-02-08 00:50

No it does not, you could be catching three out of four ( or five or more). Maybe you could try some lookbehind?

Amene Katanda's picture
Amene Katanda
Tue, 2011-02-08 23:00

Yes I noticed that: the regex is flawed. So I went on and did [a-z][A-Z]{3}[a-z][A-Z]{3} to be sure to only catch 3 capitals on each side. I came out with 10 possible matches.

Corey Richardson's picture
Corey Richardson
Tue, 2011-02-08 23:20

I usually use http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/ as my de-facto reference. It said {3} is exactly three, and {3,} was three+. I guess not!

Zuzel Vera's picture
Zuzel Vera
Wed, 2011-02-09 17:30

[A-Z]{3}[a-z][A-Z]{3} will match things like aBCDeFGHi but also things like ABCDeFDHI. You can use [^something] to avoid this second case.