php preg_match item first five character regex [closed]

亡梦爱人 提交于 2019-12-13 09:45:22

问题


I want to match item id,looks like:

a1234...
b5678...
c9876...
...

How can I write a regex only match first five characters

and first is alphabet letter, 2-5 is integer number


回答1:


preg_match_all('/[a-z]\d{2,5}/', $subject, $result, PREG_PATTERN_ORDER);
for ($i = 0; $i < count($result[0]); $i++) {
    # Matched text = $result[0][$i];
}


来源:https://stackoverflow.com/questions/17512890/php-preg-match-item-first-five-character-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!