Here is a regex - attempted by egrep and then by Python 2.7:
$ echo '/some/path/to/file/abcde.csv' | egrep '*([a-zA-Z]+).csv'
/some/path/to/file/abcde.csv
However, the same regex in Python:
re.match(r'*([a-zA-Z]+)\.csv',f )
Gives:
Traceback (most recent call last):
File "/shared/OpenChai/bin/plothost.py", line 26, in <module>
hosts = [re.match(r'*([a-zA-Z]+)\.csv',f ).group(1) for f in infiles]
File "/usr/lib/python2.7/re.py", line 141, in match
return _compile(pattern, flags).match(string)
File "/usr/lib/python2.7/re.py", line 251, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat
Doing a search reveals there appears to be a Python bug in play here:
regex error - nothing to repeat
It seems to be a python bug (that works perfectly in vim). The source of the problem is the (\s*...)+ bit.
However, it is not clear to me: what then is the workaround for my regex shown above - to make python happy?
Thanks.