php - preg_match capturing two capital letters, 3 digits and 2 capital letters, and than 7 digits -


okay have following string

"ig 449ww 6180262 250"

i want match first 2 letters, second 5 letters , numbers, , 7 numbers , want capture each of these.

so have following preg_match:

  $scanned_barcode = trim(input::get('barcode'));      if (preg_match("/([a-z]{2})\s(\d{3}[a-z]{2})\s(\d{7})/", $scanned_barcode, $found)) {         $mfg_id    = $found[1];         $game_code = $found[2];         $serial    = game::find($found[3]); } 

am doing correct? there missing? there better way this?

your regex works, easier this:

<?php      $scanned_barcode = trim(input::get('barcode'));      // 'explode' string array(), using space delimiter     // http://php.net/manual/en/function.explode.php     $found = explode(' ', $scanned_barcode);      $mfg_id    = $found[0];     $game_code = $found[1];     $serial    = game::find($found[2]);  ?> 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -