Python 正则表达式验证字符串(可能带转义符)

时间:2021-03-18 18:48:05
1.Match a string enclosed by double quotes (strings with escapes, no line break)
"[^"\\\r\n]*(?:\\.[^"\\\r\n]*)"

2.Match a string enclosed by single quotes (strings with escapes, no line break)
'[^'\\\r\n]*(?:\\.[^'\\\r\n]*)'

3.Match a string enclosed by single or double qutoes (strings with escapes, no line break)
"[^"\\\r\n]*(?:\\.[^"\\\r\n]*)"|'[^'\\\r\n]*(?:\\.[^'\\\r\n]*)'

4.Match a string enclosed by double qutoes (strings with escapes, may have escaped line break)
"[^"\\\r\n]*(?:\\(?:.|\r?\n)[^"\\\r\n]*)" 

5.Match a string enclosed by double qutoes (strings with escapes, may have line break)
"[^"\\]*(?:\\.[^"\\]*)*"