Search by keyword FORMTEXT , followed by a single space \s - after the space, the search word \w+ , followed by an alternative choice: either a bracket ( , or a space with the keyword \sFORMTEXT . To prevent keywords with spaces in the result of the sample , you can enclose them in the design back and forth looking checks: (?<=FORMTEXT\s) and (?=\(|\sFORMTEXT) respectively. The whole template will take the form: (?<=FORMTEXT\s)\w+(?=\(|\sFORMTEXT) , and with php everything will look like this:
$str = 'FORMTEXT Рыбаков(фамилия)(группа крови)(дата определения) FORMTEXT Владимир FORMTEXT Владиславович(имя, отчество)(резус)(подпись врача) FORMTEXT'; $patt = '~(?<=FORMTEXT\s)\w+(?=\(|\sFORMTEXT)~u'; preg_match_all($patt, $str, $arr); $result = $arr[0] ?? false; echo join(' ', $result);
Result:
Рыбаков Владимир Владиславович