drtj40036 2014-04-30 05:14
浏览 86
已采纳

PHP从文本中提取7个字符十六进制

I want to extract 7 hexadecimal char from text.

$text = 'Lorem ipsum dolor sit amet, 1AA69C9 consectetuer adipiscing elit. Aenean commodo ligula eget dolor. 2de7890';

preg_match_all("/^[0-9A-Fa-f]{7}$/",$text,$result);
print_r($result);

Thank you.

maybe similar to this but don't know why not working

  • 写回答

2条回答 默认 最新

  • dqsvf28682 2014-04-30 05:16
    关注

    /^[0-9A-Fa-f]{7}$/ looks for hexadecimal string at the start and end of the string.

    Remove ^ and $ and make them word boundaries instead.

    Use this:

    /\b[0-9a-f]{7}\b/i
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

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

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

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

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

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

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

客服 返回
顶部