我正在处理一个正则表达式,以匹配十六进制字符串,并在接近尾声时遇到了一些问题。我特别寻找2字节的组,它不包含长在2到8字节之间的00。我有所有的工作,除了当有少于8个字节,它将允许额外的00有时在其中。
https://regex101.com/r/jq3QpP/1/
(?!(00)+)([0-9a-fA-F]{2,8})?(?!(00)+) // This on the below text gives the following matches
C86B0200554E0200C86B02000000000000000000270000008109000000000000EC6A050079750
18881000000410000280100000000000000000001000002010400000000000000000000000000
0000000000000000000000F65FA45900000000FF0000002F0000000000000049000000403C9F5
A000000000000000000000000FFFF330000000000000F06EAE8333536
Match 1
Full match 0-8 `C86B0200`
Group 2. 0-8 `C86B0200`
Match 2
Full match 8-16 `554E0200`
Group 2. 8-16 `554E0200`
Match 3
Full match 16-21 `C86B0`
Group 2. 16-21 `C86B0`
Match 4
Full match 21-21 ``
Match 5
Full match 39-47 `02700000`
Group 2. 39-47 `02700000`在比赛1,2,5中有额外的00,在第3场比赛中,由于某种原因错过了20。如果你知道我错过了什么,请告诉我
发布于 2018-09-25 04:23:44
可以避免匹配00,方法是一次只允许两个数字的一个0:
(?:[A-F1-9][A-F0-9]|[A-F0-9][A-F1-9]){1,4}(?=(?:..)*$)https://stackoverflow.com/questions/52490392
复制相似问题