我有几种正则表达式模式,它们变得如此长而复杂,以至于难以阅读和维护。我有办法在功能保持完好的情况下以多行缩进方式编写它们吗?
例如,其中之一类似于:
pattern = r'^(.*(xxx|xxx|xxx|xxx|xxx|(xxx.*?xxx)|xxx|xxx|xxx|xxx|xxx|[xxxxxxxxxxxx\d]+(xxx|xxx|xxx|xxx[xxxxxxxxx\d]+xxx|xxx)|[xxxxxxxxx]+xxx|xxx|xxx))+(?!(xxx|xxx))([xxxxxxxxxxxxxxxxxx\d]+(?!([\da-zA-Z\-\,\/xxxxxxxxxxxx]|xxx))(xxx|xxx|xxx|xxx|xxx|xxx)+)*'
我想知道是否有这样一种写法:
pattern = r'''^(.*
(
xxx|xxx|xxx|xxx|xxx|(xxx.*?xxx)|xxx|xxx|xxx|xxx|xxx|
[xxxxxxxxxxxx\d]+(xxx|xxx|xxx|xxx[xxxxxxxxx\d]+xxx|xxx)|
[xxxxxxxxx]+xxx|xxx|xxx
)
)+
(?!(xxx|xxx))
(
[xxxxxxxxxxxxxxxxxx\d]+
(?!([\da-zA-Z\-\,\/xxxxxxxxxxxx]|xxx))
(xxx|xxx|xxx|xxx|xxx|xxx)+
)*'''
谢谢。