'a', and only if the length of the sequence is
exactly 3.
Does such a regular expression exist? If so, any ideas as to what it could
be?
--
Roger L. Cauvin
[EMAIL PROTECTED] (omit the nospam_ part)
Cauvin, Inc.
Product Management / Market Research
http://www.cauvin-inc.com
--
http
?
--
Roger L. Cauvin
[EMAIL PROTECTED] (omit the nospam_ part)
Cauvin, Inc.
Product Management / Market Research
http://www.cauvin-inc.com
--
http://mail.python.org/mailman/listinfo/python-list
clear what exactly the intent is, no...
Sorry for the confusion. The correct pattern should reject all strings
except those in which the first sequence of the letter 'a' that is followed
by the letter 'b' has a length of exactly three.
Hope that's clearer . . . .
--
Roger L. Cauvin
[EMAIL
Sybren Stuvel [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Roger L. Cauvin enlightened us with:
I'm looking for a regular expression that matches the first, and
only the first, sequence of the letter 'a', and only if the length
of the sequence is exactly 3.
Your request
.
r = re.compile([^a]*a{3}b+(a+b*)*)
matches = [s for s in listOfStringsToTest if r.match(s)]
Wow, I like it, but it allows some strings it shouldn't. For example:
xyz123aabbaaab
(It skips over the two-letter sequence of 'a' and matches 'bbaaab'.)
--
Roger L. Cauvin
[EMAIL PROTECTED] (omit
Christos Georgiou [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
On Thu, 26 Jan 2006 14:09:54 GMT, rumours say that Roger L. Cauvin
[EMAIL PROTECTED] might have written:
Say I have some string that begins with an arbitrary sequence of
characters
and then alternates repeating
accept, since the 'a' between the 'x' and the 'y' is not
directly followed by the letter 'b'.
--
Roger L. Cauvin
[EMAIL PROTECTED] (omit the nospam_ part)
Cauvin, Inc.
Product Management / Market Research
http://www.cauvin-inc.com
--
http://mail.python.org/mailman/listinfo/python-list
Peter Hansen [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Roger L. Cauvin wrote:
Sorry for the confusion. The correct pattern should reject all strings
except those in which the first sequence of the letter 'a' that is
followed by the letter 'b' has a length of exactly three
the job
(they have in every case but one).
--
Roger L. Cauvin
[EMAIL PROTECTED] (omit the nospam_ part)
Cauvin, Inc.
Product Management / Market Research
http://www.cauvin-inc.com
--
http://mail.python.org/mailman/listinfo/python-list
Fredrik Lundh [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Roger L. Cauvin wrote:
Good suggestion. Here are some test cases:
xyz123aaabbab accept
xyz123aabbaab reject
xayz123aaabab accept
xaaayz123abab reject
xaaayz123aaabab accept
$ more test.py
import re
print got
Christos Georgiou [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
On Thu, 26 Jan 2006 16:41:08 GMT, rumours say that Roger L. Cauvin
[EMAIL PROTECTED] might have written:
Good suggestion. Here are some test cases:
xyz123aaabbab accept
xyz123aabbaab reject
xayz123aaabab accept
Christos Georgiou [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
On Thu, 26 Jan 2006 16:26:57 GMT, rumours say that Roger L. Cauvin
[EMAIL PROTECTED] might have written:
Christos Georgiou [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
On Thu, 26 Jan 2006 14:09:54 GMT
Christos Georgiou [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
On Thu, 26 Jan 2006 18:01:07 +0100, rumours say that Fredrik Lundh
[EMAIL PROTECTED] might have written:
Roger L. Cauvin wrote:
Good suggestion. Here are some test cases:
xyz123aaabbab accept
xyz123aabbaab reject
Christos Georgiou [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
On Thu, 26 Jan 2006 17:09:18 GMT, rumours say that Roger L. Cauvin
[EMAIL PROTECTED] might have written:
Thanks, but the second test case I listed contained a typo. It should
have
contained a sequence of three
Fredrik Lundh [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Roger L. Cauvin wrote:
$ python test.py
gotexpected
---
accept accept
reject reject
accept accept
reject reject
accept accept
Thanks, but the second test case I listed contained a typo
Michael Spencer [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Roger L. Cauvin wrote:
xyz123aaabbab accept
xyz123aabbaaab reject
xayz123aaabab accept
xaaayz123abab reject
xaaayz123aaabab accept
This passes your tests. I haven't closely followed the thread for other
.
^([^b]|((?!a)b))*aaab+[ab]*$
Looks good, although I've been unable to find a good explanation of the
negative lookbehind construct (?. How does it work?
--
Roger L. Cauvin
[EMAIL PROTECTED] (omit the nospam_ part)
Cauvin, Inc.
Product Management / Market Research
http://www.cauvin-inc.com
Peter Hansen [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Roger L. Cauvin wrote:
Michael Spencer [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Roger L. Cauvin wrote:
xyz123aaabbab accept
xyz123aabbaaab reject
xayz123aaabab accept
xaaayz123abab reject
xaaayz123aaabab
18 matches
Mail list logo