這實際上是可行的嗎?我有一些很長的正則表達式模式規則,很難理解,因爲它們一次不適合屏幕顯示。例如:如何在Python中將長正則表達式規則分割爲多行
test = re.compile('(?P<full_path>.+):\d+:\s+warning:\s+Member\s+(?P<member_name>.+)\s+\((?P<member_type>%s)\) of (class|group|namespace)\s+(?P<class_name>.+)\s+is not documented' % (self.__MEMBER_TYPES), re.IGNORECASE)
反斜槓或三重引號不起作用。
編輯。我最終使用了VERBOSE。以下是正則表達式現在的樣子:
test = re.compile('''
(?P<full_path> # Capture a group called full_path
.+ # It consists of one more characters of any type
) # Group ends
: # A literal colon
\d+ # One or more numbers (line number)
: # A literal colon
\s+warning:\s+parameters\sof\smember\s+ # An almost static string
(?P<member_name> # Capture a group called member_name
[ #
^: # Match anything but a colon (so finding a colon ends group)
]+ # Match one or more characters
) # Group ends
( # Start an unnamed group
:: # Two literal colons
(?P<function_name> # Start another group called function_name
\w+ # It consists on one or more alphanumeric characters
) # End group
)* # This group is entirely optional and does not apply to C
\s+are\snot\s\(all\)\sdocumented''', # And line ends with an almost static string
re.IGNORECASE|re.VERBOSE) # Let's not worry about case, because it seems to differ between Doxygen versions
're.VERBOSE' [示例](HTTP://計算器.com/questions/7957846/python-regex-意思/ 7958248#7958248) – jfs
@JF塞巴斯蒂安:我必須給re.DEBUG +1,這會讓我的生活在未來變得更加輕鬆! – Makis
@ J.F。Sebastian:我在鏈接後面提出了你的回答,因爲最終我仍然使用它,即使它需要更多的編輯(必須確保每個空白標記都正確)。 – Makis