Good day. The beginner in regular expressions, but I want to understand. There is a string, it needs to be reduced to one type, i.e. leave only the name. Options: http://vk.com/id62334653 vk.com/id62334653 id62334653, etc.
When working with value:
$data = 'http://vk.com/id62334653'; $pattern = '/((http(s)?:\/\/)?(new\.)?(m\.)?(vk\.com\/)?)([a-z_0-9.]*)?(.*)?/ius'; $data = preg_replace($pattern, '[$7]', trim($data)); echo '<br />'.$data2.'='.$data;
No problem, the result: http://vk.com/id62334653=[id62334653]
But if the string:
$data = 'ΠΠΈΡ
Π°ΠΈΠ» Π£ΡΠΏΠ΅Π½ΡΠΊΠΈΠΉ http://vk.com/m.uspenskiy';
result: Mikhail Uspensky [m.uspenskiy]
They advised to do this:
$pattern = '/((http(s)?:\/\/)?(new\.)?(m\.)?(vk\.com\/)?)([a-z_0-9.]*)?(.*)?/ius'; $data = preg_replace($pattern, '[$7]', trim($data)); echo '<br />'.$data2.'='.$data;
But the problem is that a blank line is issued here if we remove the "?" after (http (s)?: //), then everything is fine, but then expressions like "vk.com/m.uspenskiy" do not pass, because there is no "http" in it, but this input option is also possible.
A question how to consider all this data? those. How to consider the options: "vk.com/m.uspenskiy" and 'Mikhail Uspensky http://vk.com/m.uspenskiy ', so that the result is "m.uspenskiy"?