In article ,
Phlip wrote:
>
>Thanks all for playing! And as usual I forgot a critical detail:
>
>I'm writing a matcher for a Morelia /viridis/ Scenario step, so the
>matcher must be a single regexp.
Why? (You're apparently the author of Morelia, but I don't really
understand it.)
--
Aahz (a...
On 25/11/2010 19:57, Phlip wrote:
Accepting input from a human is fraught with dangers and edge cases.
Here's a non-regex solution
Thanks all for playing! And as usual I forgot a critical detail:
I'm writing a matcher for a Morelia /viridis/ Scenario step, so the
matcher must be a single re
> Accepting input from a human is fraught with dangers and edge cases.
> Here's a non-regex solution
Thanks all for playing! And as usual I forgot a critical detail:
I'm writing a matcher for a Morelia /viridis/ Scenario step, so the
matcher must be a single regexp.
http://c2.com/cgi/wiki?Mor
On 25/11/2010 04:46, Phlip wrote:
HypoNt:
I need to turn a human-readable list into a list():
print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and
c').groups()
That currently returns ('c',). I'm trying to match "any word \w+
followed by a comma, or a final word preceded by and.
On 11/24/2010 10:46 PM, Phlip wrote:
> HypoNt:
>
> I need to turn a human-readable list into a list():
>
>print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and
> c').groups()
>
> That currently returns ('c',). I'm trying to match "any word \w+
> followed by a comma, or a final wor
Phlip,
> I'm trying to match "any word \w+ followed by a comma, or a final word
> preceded by and."
Here's a non-regex solution that handles multi-word values and multiple
instances of 'and' (as pointed out by Alice). The posted code could be
simplified via list comprehension - I chose the more
Now that I think about it, and can be stripped using a callback
function as the 'normalize' argument to my KeywordProcessor class:
def normalize(value):
value = value.strip()
if value.startswith("and"):
value = value[3:]
return value
parser = KeywordProcessor(',', normalize=no
Accepting input from a human is frought with dangers and edge cases. ;)
Some time ago I wrote a regular expression generator that creates
regexen that can parse arbitrarily delimited text, supports quoting (to
avoid accidentally separating two elements that should be treated as
one), and work
--- On Thu, 11/25/10, Phlip wrote:
> From: Phlip
> Subject: a regexp riddle: re.search(r'
> To: python-list@python.org
> Date: Thursday, November 25, 2010, 8:46 AM
> HypoNt:
>
> I need to turn a human-readable list into a list():
>
> print re.search(r'(
HypoNt:
I need to turn a human-readable list into a list():
print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and
c').groups()
That currently returns ('c',). I'm trying to match "any word \w+
followed by a comma, or a final word preceded by and."
The match returns 'a, bbb, and c',
10 matches
Mail list logo