An escape error of re.py (re.error: bad escape \s at position 0) in "utils/logloader.py" based on Python3.7
See original GitHub issueDear authors, Thanks for your work. When I ran the file, “MoLFI_demo.py”, based on Python3.7, I got the error as following.
Traceback (most recent call last):
File "~/anaconda3/envs/tf/lib/python3.7/sre_parse.py", line 1021, in parse_template
this = chr(ESCAPES[this][1])
KeyError: '\\s'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "MoLFI_demo.py", line 14, in <module>
parser.parse(log_file)
File "../logparser/MoLFI/MoLFI.py", line 41, in parse
loader = logloader.LogLoader(self.log_format, self.n_workers)
File "../logparser/utils/logloader.py", line 38, in __init__
self.headers, self.regex = self._generate_logformat_regex(self.logformat)
File "../logparser/utils/logloader.py", line 79, in _generate_logformat_regex
splitter = re.sub(' +', '\s+', splitters[k])
File "~/anaconda3/envs/tf/lib/python3.7/re.py", line 192, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "~/anaconda3/envs/tf/lib/python3.7/re.py", line 309, in _subx
template = _compile_repl(template, pattern)
File "~/anaconda3/envs/tf/lib/python3.7/re.py", line 300, in _compile_repl
return sre_parse.parse_template(repl, pattern)
File "~/anaconda3/envs/tf/lib/python3.7/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’d be grateful if you could help me.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Python 3.7.4: 're.error: bad escape \s at position 0'
into a regular string. I checked the Python 3.7 documentation, and it appears that \s is still the escape sequence for white space....
Read more >Gotchas - Python re(gex)? - learnbyexample
Example based guide to mastering Python regular expressions. ... re.sub(r',', r'\x7c', '1,2') re.error: bad escape \x at position 0 >>> re.sub(r',', ...
Read more >Issue 47023: re.sub shows key error on regex escape chars ...
error ('bad escape %s' % this, len(this))" should probably be "from None", since as @mrabarnett notes the KeyError is an implementation detail.
Read more >Python Re Escape - Finxter
Challenge: Some characters have a special meaning in Python strings and regular expressions. Say you want to to search for string "(s)" but...
Read more >[Example code]-How to fix bad escape regex error (python re)
I would try to achieve to convert that date to 05/26/2012. I tried to achieve this without using DateTime but with regex. I...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can also try replacing import re to import regex as re
Just adding this in case someone else has this problem in 2022 when using python 3.8.10. I changed the following line:
splitter = re.sub(' +', '\s+', splitters[k])
to
splitter = re.sub(' +', '\\\s+', splitters[k])
and that fixed it. Note that I changed this only in the function
def _generate_logformat_regex(self, logformat):
of the fileSpell/Spell.py
(because I was using spell) and not inutils/logloader.py
.