$newSubject = preg_replace("#^(?:.+:)?\s*(.+)\s*$#", "$1", $subject);
if present, all non-colon characters are truncated in the passive group (?:) , also, all characters that are not in the group between the supposed spaces are truncated. at the output we have only a string that falls into the group, on which the original string changes
example:
$ cat example.php <?php foreach ([ "number: что угодно", "что угодно 2", "number: что угодно 3" ] as $subject) { $newSubject = preg_replace("#^(?:.+:)?\s*(.+)\s*$#", "$1", $subject); echo "$newSubject\n"; } $ php example.php что угодно что угодно 2 что угодно 3