Alex Martelli wrote:
Christoph Conrad [EMAIL PROTECTED] wrote:
Hello Roger,
since the length of the first sequence of the letter 'a' is 2. Yours
accepts it, right?
Yes, i misunderstood your requirements. So it must be modified
essentially to that what Tim Chase wrote:
m =
How about:
pattern = re.compile('^([^a]|(a+[^ab]))*aaab')
Which basically says, precede with arbitrarily many non-a's
or a sequences ending in non-b, then must have 3 as followed by a b.
cases = [xyz123aaabbab, xayz123aaabab, xaaayz123aaabab,
xyz123babaaabab, xyz123aabbaaab,
Say I have some string that begins with an arbitrary sequence of characters
and then alternates repeating the letters 'a' and 'b' any number of times,
e.g.
xyz123aaabbaaabaaaabb
I'm looking for a regular expression that matches the first, and only the
first, sequence of the letter
Hello Roger,
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.
import sys, re, os
if __name__=='__main__':
m = re.search('a{3}', 'xyz123aaabbaaaabaaabb')
print
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 is ambiguous:
1) You're looking for the first, and only the first, sequence of
Say I have some string that begins with an arbitrary
sequence of characters and then alternates repeating the
letters 'a' and 'b' any number of times, e.g.
xyz123aaabbaaabaaaabb
I'm looking for a regular expression that matches the
first, and only the first, sequence of the
Tim Chase [EMAIL PROTECTED] wrote:
...
I'm not quite sure what your intent here is, as the
resulting find would obviously be aaa, of length 3.
But that would also match ''; I think he wants negative loobehind
and lookahead assertions around the 'aaa' part. But then there's the
spec
Christoph Conrad [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Hello Roger,
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.
import sys, re, os
if
Alex Martelli [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Tim Chase [EMAIL PROTECTED] wrote:
...
I'm not quite sure what your intent here is, as the
resulting find would obviously be aaa, of length 3.
But that would also match ''; I think he wants negative loobehind
and
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 the letters 'a' and 'b' any number of times,
e.g.
xyz123aaabbaaabaaaabb
Hello Roger,
since the length of the first sequence of the letter 'a' is 2. Yours
accepts it, right?
Yes, i misunderstood your requirements. So it must be modified
essentially to that what Tim Chase wrote:
m = re.search('^[^a]*a{3}b', 'xyz123aabbaaab')
Best wishes from germany,
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 is
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.
Ah...a little more clear.
r = re.compile([^a]*a{3}b+(a+b*)*)
matches = [s for s
Tim Chase [EMAIL PROTECTED] 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.
Ah...a little more clear.
r =
Hallo Alex,
r = re.compile([^a]*a{3}b+(a+b*)*) matches = [s for s in
listOfStringsToTest if r.match(s)]
Unfortunately, the OP's spec is even more complex than this, if we are
to take to the letter what you just quoted; e.g. aazaaab SHOULD match,
Then it's again a{3}b, isn't it?
Freundliche
Tim Chase [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
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.
Ah...a little more clear.
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 the
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'.)
Anchoring it to the beginning/end might
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.
Hope that's clearer . . . .
Examples are a *really* good way to
Tim Chase [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
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'
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.
Christoph Conrad [EMAIL PROTECTED] wrote:
Hello Roger,
since the length of the first sequence of the letter 'a' is 2. Yours
accepts it, right?
Yes, i misunderstood your requirements. So it must be modified
essentially to that what Tim Chase wrote:
m = re.search('^[^a]*a{3}b',
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, rumours say that Roger L. Cauvin
[EMAIL PROTECTED] might have written:
Say I
Alex Martelli [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Tim Chase [EMAIL PROTECTED] 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
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
xaaayz123abab reject
xaaayz123aaabab accept
Applying my last regex to your test
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 gotexpected
print --
testsuite = (
(xyz123aaabbab, accept),
On Thu, 26 Jan 2006 16:26:57 GMT in comp.lang.python, Roger L.
Cauvin [EMAIL PROTECTED] wrote:
Christos Georgiou [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
[...]
Is this what you mean?
^[^a]*(a{3})(?:[^a].*)?$
Close, but the pattern should allow arbitrary sequence of
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
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
xayz123aaabab accept
xaaayz123abab reject
xaaayz123aaabab accept
$ more
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,
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 of the letter 'a'. The test cases should be:
xyz123aaabbab accept
xyz123aabbaaab
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
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. It should have
contained a sequence of three of the letter 'a'. The test
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 of the
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. It
The below seems to pass all the tests you threw at it (taking the
modified 2nd test into consideration)
One other test that occurs to me would be
xyz123aaabbaaabab
where you have aaab in there twice.
-tkc
import re
tests = [
(xyz123aaabbab,True),
(xyz123aabbaaab, False),
Roger L. Cauvin wrote:
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
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
Tim Chase [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
The below seems to pass all the tests you threw at it (taking the modified
2nd test into consideration)
One other test that occurs to me would be
xyz123aaabbaaabab
where you have aaab in there twice.
Good suggestion.
xyz123aaabbaaabab
where you have aaab in there twice.
Good suggestion.
I assumed that this would be a valid case. If not, the
expression would need tweaking.
^([^b]|((?!a)b))*aaab+[ab]*$
Looks good, although I've been unable to find a good
explanation of the negative lookbehind
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 accept
This passes your tests. I haven't closely followed the thread
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
Christoph Conrad [EMAIL PROTECTED] wrote:
Hallo Alex,
r = re.compile([^a]*a{3}b+(a+b*)*) matches = [s for s in
listOfStringsToTest if r.match(s)]
Unfortunately, the OP's spec is even more complex than this, if we are
to take to the letter what you just quoted; e.g. aazaaab SHOULD
44 matches
Mail list logo