파이썬이 여러 분리 문자로 문자열을 분할하려하지만 이스케이프 처리 된 백 슬래시 문자에 대해 비명을 지르고 있습니다.파이썬 re.split() 백 슬래시 이스케이프
내가 파이썬에서 백 슬래시를 이스케이프 보았을 때로 변경하는 것을 확실하지 않다,이
import re
def get_asset_str(in_str):
split = re.split(' |/|\\' , in_str)
Traceback (most recent call last):
File "AssetCheck.py", line 15, in <module>
get_asset_str(line)
File "AssetCheck.py", line 4, in get_asset_str
split = re.split(' |/|\\' , in_str)
File "C:\Python27\lib\re.py", line 167, in split
return _compile(pattern, flags).split(string, maxsplit)
File "C:\Python27\lib\re.py", line 244, in _compile
raise error, v # invalid expression
sre_constants.error: bogus escape (end of line)
정규 표현식에서 이스케이프 처리중인 문자를 찾고 있기 때문입니다. –
는 원시 문자열을 사용합니다 :'r '|/| \\''그리고 하나의 문자 대신에 더 나은 문자 클래스를 사용하십시오 :'r '[/ \\]'' –
'|/| \ \\\ '' –