a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')
Alice Bevan–McGregor
alice at gothcandy.com
Thu Nov 25 05:04:56 EST 2010
- Previous message (by thread): a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')
- Next message (by thread): a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
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=normalize, result=list)
— Alice.
- Previous message (by thread): a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')
- Next message (by thread): a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Python-list
mailing list