regexp qns

James Stroud jstroud at mbi.ucla.edu
Fri Jan 19 23:48:39 EST 2007


eight02645999 at yahoo.com wrote:
> hi
> suppose i have a string like
> 
> test1?test2t-test3*test4*test5$test6#test7*test8
> 
> how can i construct the regexp to get test3*test4*test5 and
> test7*test8, ie, i want to match * and the words before and after?
> thanks
> 


py> import re
py> s = 'test1?test2t-test3*test4*test5$test6#test7*test8'
py> r = re.compile(r'(test\d(?:\*test\d)+)')
py> r.findall(s)
['test3*test4*test5', 'test7*test8']

James



More information about the Python-list mailing list