一、問題描述
程序中包含正則表達式,如下:
pattern = '([_a-zA-Z0-9\u4e00-\u9fa5\`\~\!\@\#\$\%\^\&\*\(\)\_\+\-\=\[\]\{\}\\\|\;\'\'\:\"\"\,\.\/\<\>\?]{0,}'
執行程序的時候報錯:ValueError: unsupported format character '\' (0x5c) at index 29
二、解決方案
正則表達式有問題,在\%后面再加一個%,即為:
pattern = '([_a-zA-Z0-9\u4e00-\u9fa5\`\~\!\@\#\$\%%\^\&\*\(\)\_\+\-\=\[\]\{\}\\\|\;\'\'\:\"\"\,\.\/\<\>\?]{0,}'
三、問題原因
python2和python3的區別,python3需要寫后面一種