'*' Causes the resulting RE to match 0 or more repetitions of the
preceding RE, as many repetitions as are possible. ab* will match ‘a’,
‘ab’, or ‘a’ followed by any number of ‘b’s.
'?' Causes the resulting RE to match 0 or 1 repetitions of the
preceding RE. ab? will match either ‘a’ or ‘ab’.
'\' Either escapes special characters (permitting you to match
characters like '*', '?', and so forth), or signals a special
sequence. so to check '\' you need to put it as '\'. For example, to
match a literal backslash, one might have to write '\\' as the
pattern string, because the regular expression must be \, and each
backslash must be expressed as \ inside a regular Python string
literal.
您有机会查看python文档吗? 你需要知道:
如果您需要知道如何在python中使用regex: Python string.replace regular expression
试试这个:
替换为:
Demo
示例代码:
Run it
相关问题 更多 >
编程相关推荐