Facebook profile URL regular expression

Given the following Facebook profile and page URLs, my intent is to extract profile ids or usernames into the first match position.

http://www.facebook.com/profile.php?id=123456789  
http://www.facebook.com/someusername  
www.facebook.com/pages/Regular-Expressions/207279373093  

The regex I have so far looks like this:

(?:http:\/\/)?(?:www.)?facebook.com\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[?\w\-]*\/)?(?:profile.php\?id=(\d.*))?([\w\-]*)?

Which produces the following results:

Result 1:

  1. 123456789

Result 2:

  1. someusername

Result 3:

  1. 207279373093

The ideal outcome would look like:

Result 1:

  1. 123456789

Result 2:

  1. someusername

Result 3:

  1. 207279373093

That is to say, I'd like to have the profile identifier to always be returned in the first position.

It would also be ideal of www.facebook.com/ and facebook.com/ didn't match either.

20
задан simhumileco 17 October 2019 в 16:44
поделиться