I have very simple python script to match some special characters like -,+,-,. But Im not getting expected result while using regex \ to match a single '\' char.
import re
pat = r'[-+*\\]'
text = 'fdkjdfk\sdsdd'
if re.search(pat,text):
print re.search(pat,text).group()
else:
print "not found"
On running above code , it prints 'not found' It seems I am doing some mistake 开发者_JAVA百科here , any help appreciated !!!
\
is an escape character.
Try escaping it:
text = 'fdkjdfk\\sdsdd'
精彩评论