-3

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

jk jk
  • 1,027
  • 2
  • 13
  • 28
  • 1
    Is there anything you have done to try to solve this problem? We will be more willing to answer your question if you tell us what you have tried so far. (Helpful links for asking better questions: [ask], [help]) – tckmn Jul 07 '13 at 14:15
  • possible duplicate of [Regex for 2 letters followed by 4 digits](http://stackoverflow.com/questions/9296056/regex-for-2-letters-followed-by-4-digits) – mario Jul 07 '13 at 14:15
  • * See also [Open source RegexBuddy alternatives](http://stackoverflow.com/questions/89718/is-there) and [Online regex testing](http://stackoverflow.com/questions/32282/regex-testing) for some helpful tools, or [RegExp.info](http://regular-expressions.info/) for a nicer tutorial. – mario Jul 07 '13 at 14:16

1 Answers1

0
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];
}
Andy Gee
  • 3,149
  • 2
  • 29
  • 44