我想知道是否有可能创建一个正则表达式来解析我试图解析的特定协议。
这是规矩。
示例
发布于 2014-10-03 06:27:12
您可以使用
/(?:=(?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
)*
)https://stackoverflow.com/questions/26171480
复制相似问题