doukang7501 2015-04-30 16:04
浏览 113
已采纳

PHP在字符串中找到28个字符的十六进制正则表达式

In a very long line, i need to find a regex that matches something like this:

01 02 03 04 05 06 07 08 09 10 11 12 13 14

now, that string is always made of hexadecimal characters, so it can be something like this also:

ab ba 1a 2f 3c 2a 1d 35 32 12 34 78 90 11

only thing that all of them have in common is that they come in 14-pair or 28 character hex values

How can it be done with PHP?

Have tried a few combinations, for example:

preg_match('/[a-f0-9]{2}/i', $data, $matches);

but none that covers all possibilities.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongxie7683 2015-04-30 16:11
    关注

    Here's a regex pattern that should match what you should need

    (([a-f0-9]{2} ){27}|([a-f0-9]{2} ){13})[a-f0-9]{2}
    

    Example

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部