Home javascript Regular expression to the address of the VK page

Regular expression to the address of the VK page

Author

Date

Category

Help me write a JavaScript regular expression. Here’s what data should be skipped:

http://vk.com/user/
http://vk.com/user
vk.com/user/
vk.com/user
www.vk.com/user/
www.vk.com/user

It is clear that “user” is any text. It could also be “id123456”.


Answer 1, authority 100%

Here’s another working option:

^ (https?: \ / \ /)? (www \.)? vk \ .com \ / (\ w | \ d) +? \ /? $

Answer 2, authority 92%

^ (http: \ / \ / | https: \ / \ /)? (www.)? (vk \. com | vkontakte \ .ru) \ / (id \ d | [a-zA-Z0-9 _.]) + $

Answer 3

In fact, here’s a better solution

(https {0,1}: \ / \ /)? (www \.)? (vk.com \ / ) (id \ d | [a-zA-z] [a-zA-Z0-9 _.] {2,})

Since username cannot start with a number, like this: https://vk.com/1111111

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions