regular expression concatination help

Curtis Jensen cjensen at bioeng.ucsd.edu
Mon Sep 17 13:23:48 EDT 2001


I would like to match one regular expression concatenated with another
regular expression 0 or 1 times. "re0" is the first regular expression,
"re1" is the second.  re0 includes the empty string; implying that
"re0+re1?" would include everything that "re1?" includes.  In the
excerpt below, I would like to match str0+str1, but I can't make it
happen.

Any help in fixing this would be appreciated.  Thanks.

I have:
>>> import regex
>>> str0 = '1,2,31'
>>> str1= '1.2..2:0.2'
>>> re0 = '\([0-9],?\)*'
>>> re1 = '[0-9]+\.?[0-9]*\.\.[0-9]+\.?[0-9]*\(:[0-9]+\.?[0-9]*\)?'
>>> len(str0)
6
>>> len(str1)
10
>>> regex.match( re0, '' )
0
>>> regex.match( re0, str0 )
6
>>> regex.match( '\(' + re1 + '\)?', str1 )
10
>>> regex.match( re0 + '\(' + re1 + '\)?', str1 )
1
>>> regex.match( re0 + '\(' + re1 + '\)?', str0 )
6
>>> regex.match( re0 + '\(' + re1 + '\)?', str0 + str1 )
7
>>>



More information about the Python-list mailing list