Friday, 23 August 2013

python re.sub missing group name error

python re.sub missing group name error

im going crazy i have no idea why im getting this error:
Traceback (most recent call last):
File "File.py", line 154, in <module>
main()
File "File.py", line 143, in main
dld = work()
File "File.py", line 100, in work
string1= re.sub(find_dev_line, dev_line_to_replace, string1)
File "C:\Program Files (x86)\python27\lib\re.py", line 151, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "C:\Program Files (x86)\python27\lib\re.py", line 270, in _subx
template = _compile_repl(template, pattern)
File "C:\Program Files (x86)\python27\lib\re.py", line 257, in
_compile_repl
raise error, v # invalid expression
sre_constants.error: missing group name
with these lines of code:
dev_line_searchterm = "^.+"+devname+".+$"
dev_line_to_replace = str(os.path.join(start_dir, "Downloads", devname,
filename))
find_dev_line = re.compile(dev_line_searchterm, re.MULTILINE)
string1= re.sub(find_dev_line, dev_line_to_replace, string1)
I dont have any groups in these lines, why am i getting the error? Thanks

No comments:

Post a Comment