我想知道是否可以创建一个解析特定协议的正则表达式 我试图解析。
以下是规则。
实施例
答案 0 :(得分:0)
您可以使用
/(?:=(?P<channel>[2-5])|^)(?P<data>(?:(?===)==|(?!=(?:[2-5]|\Z)).)*)/ms
您将在群组channel
(如果有)中找到该频道,其余的则在群组data
中找到。
说明:
(?: # first, match a "=" channel...
=
(?P<channel>
[2-5]
)
| #...or assert position at the start of the string
^
)
(?P<data> # next, capture the data in a group
(?: # repeat the following as often as possible:
(?= # if there's an escaped "=" ("=="), consume it
==
)
==
|
(?! # otherwise, if...
=
(?: #...the next match doesn't start here...
[2-5]
| #...and the string doesn't end with "=" here...
\Z
)
)
. #...consume a single character
)*
)