Help with the regular schedule, which is from the line:

Заявка: № 142898 от Аптека №Дн028 г.Кривой Рог, ул.К.Маркса, 19 (Задача №239735) 

selects only # DN028. Search criteria - necessarily "No.", one or several letters, one or several numbers - all without a space, the phrase is separated by spaces on the left and on the right.

    2 answers 2

    Use preg_match () (or preg_match_all () - if you need to find all entries in the substring) :

     $str = 'Заявка: № 142898 от Аптека №Дн028 г.Кривой Рог, ул.К.Маркса, 19 (Задача №239735)'; preg_match('~№\pL+\d+~iu', $str, $arr); var_dump($arr); // №Дн028 

      We have the string:

       $string = 'Заявка: № 142898 от Аптека №Дн028 г.Кривой Рог, ул.К.Маркса, 19'; 

      And the following regular expression:

       preg_match('/№[а-яА-Я]+[0-9]+/', $string, $matches); 

      Regular expression details :

      • - the first character is always No.

      • [а-яА-Я]+ - one or more Russian letters of different register

      • [0-9]+ - one or more digits in the range from 0 до 9

      Next, we display

       print_r($matches); 

      The result is:

       Array ( [0] => №Дн028 )