Điều này thực sự có thể thực hiện được không? Tôi có một số quy tắc mẫu regex rất dài mà khó hiểu vì chúng không vừa với màn hình cùng một lúc. Ví dụ:Cách tách quy tắc biểu thức chính quy dài thành nhiều dòng trong 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)
Dấu gạch chéo ngược hoặc dấu ngoặc kép sẽ không hoạt động.
EDIT. Tôi đã kết thúc bằng cách sử dụng VERBOSE hơn. Dưới đây là cách mẫu regexp trông như sau:
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' [ví dụ] (http: // stackoverflow .com/questions/7957846/python-regex-meaning/7958248 # 7958248) – jfs
@JF Sebastian: Tôi đã phải đưa ra 1 cho re.DEBUG một mình, điều đó sẽ làm cho cuộc sống của tôi dễ dàng hơn nhiều trong tương lai! – Makis
@ J.F.Sebastian: Tôi upvoted câu trả lời của bạn ở phía sau liên kết bởi vì cuối cùng tôi vẫn kết thúc bằng cách sử dụng nó mặc dù nó yêu cầu chỉnh sửa nhiều hơn (phải chắc chắn rằng mỗi khoảng trắng được đánh dấu chính xác). – Makis