pyhton特殊字符如何写出来,特殊字符split如何切割解决,python2.7+ , 3.7+通用

哪11个特殊字符?

    $,(),*,+,.,[,?,\,^, {,|

如何使用特殊字符?

    详见示例代码

示例代码

 
#decoding:utf-8

#ex_re_unnormalSymbol.py

self_file = __file__ #save current file absolute path


import re #使用正则表达式模块


#########11个特殊字符$,(),*,+,.,[,?,\,^, {,|#########

print u"要匹配文本中的这些特殊字符时,正则表达式中要用转义字符先转义一下"

text = "hello world {*_*?}"

print text

print u"请抠出上面文本中的{*_*?}"

ret = re.findall(r"\{\*_\*\?}", text)

print ret #['{*_*?}']

print ret[0] #{*_*?}

print "\nexit %s" % self_file

编译执行

spit 如何切割

*   \    ”  *  等等特殊字符 通过  反斜杠\ 加上原来的字符即可 

   # 特殊字符在切割时候通过反斜杠加特殊字符即可   \”  ==> ”
   msg = ((str(req.text).split("sig")[1]).split("\"")[2])

猜你喜欢

转载自blog.csdn.net/qq_34173549/article/details/81544199