admin管理员组

文章数量:1611136

re.error: bad escape \s at position 0

问题展示:

Traceback (most recent call last):
File “C:/workspace/DeepLog-master/DeepLog/ParseByShell.py”, line 19, in
parser.parse(log_file)
File “C:\workspace\DeepLog-master\DeepLog\logparser\Spell\Spell.py”, line 231, in parse
self.load_data()
File “C:\workspace\DeepLog-master\DeepLog\logparser\Spell\Spell.py”, line 276, in load_data
headers, regex = self.generate_logformat_regex(self.logformat)
File “C:\workspace\DeepLog-master\DeepLog\logparser\Spell\Spell.py”, line 312, in generate_logformat_regex
splitter = re.sub(r’ +', ‘\s+’, splitters[k])
File “C:\anaconda3\lib\re.py”, line 192, in sub
return _compile(pattern, flags).sub(repl, string, count)
File “C:\anaconda3\lib\re.py”, line 309, in _subx
template = _compile_repl(template, pattern)
File “C:\anaconda3\lib\re.py”, line 300, in _compile_repl
return sre_parse.parse_template(repl, pattern)
File “C:\anaconda3\lib\sre_parse.py”, line 1024, in parse_template
raise s.error(‘bad escape %s’ % this, len(this))
re.error: bad escape \s at position 0

解决方案:

I dealt with a similar issue (sre_constants.error: bad escape \p at position 1) and the solution was to
import regex and use regex.sub instead of re.sub.
使用regex代替re。即

import regex as re

本文标签: ErrorPythonbadPositionEscape