Text: https://vk.com/id1
It is necessary to select in the text id 'unit'
Text: https://vk.com/id33
It will be 33
Text: https://vk.com/id1
It is necessary to select in the text id 'unit'
Text: https://vk.com/id33
It will be 33
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
You can use online constructors for writing regular expressions, for example http://uvsoftium.ru/php/regexp.php
There is a detailed reference on writing.
In your case, it looks like: vk\.com\/id(\d+)
Something like this:
/https?:\/\/vk\.com\/id(-?\d+)/ And maybe so:
/https?:\/\/vk\.com\/(?:id)?(-?\w+)/ Example in php:
$vk_url = "https://vk.com/id33"; $string = preg_replace("/https?:\/\/vk\.com\/id/", '', $vk_url); As an example without a request to the VK API, but it is better to check through the VK API to remove cases when
screen_namestarts withid
But now screen_name is very often used and it is necessary to check it with id or screen_name and already considering this, build a request to the API and check and write down either id or numbers:
$vk_url = "https://vk.com/id33"; $string = preg_replace("/https?:\/\/vk\.com\/(id:?)?/", '', $vk_url); Source: https://ru.stackoverflow.com/questions/599716/
All Articles