I know there are a bunch of other regex questions, but I was hoping someone could point out what is wrong with my regex. I have done some research into it and it looks like it should work. I used rubular to test it, yes I know that is regex for ruby, but the same rules I used should apply to python from what it looks like in the python docs
Currently I have
a = ["SDFSD_SFSDF234234","SDFSDF_SDFSDF_234324","TSFSD_SDF_213123"]
c = [re.sub(r'[A-Z]+', "", x) for x in a]
which returns
['SDFSD_SFSDF', 'SDFSDF_SDFSDF_', 'TSFSD_SDF_']
But I want it to return
['SDFSD_SFSDF', 'SDFSDF_SDFSDF', 'TSFSD_SDF']
I try to use this regex
c = [re.sub(r'$?_[^A-Z_]+', "", x) for x in a]
but I am getting this error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/re.py", line 151, in sub
return _compile(pattern, 0).sub(repl, string, count)
File "/usr/lib64/python2.6/re.py", line 245, in _compile
raise error, v # invalid expression
Can anyone help me figure out what I am doing wrong?
c
should be['_234234', '__234324', '__213123']
. – arshajii Jul 17 '13 at 21:59