Facebook profile URL regular expression

I made a gist a while back that works fine against the given examples:

# Matches patterns such as:
#    http://www.facebook.com/my_page_id => my_page_id
#    http://www.facebook.com/#!/my_page_id => my_page_id
#    http://www.facebook.com/pages/Paris-France/Vanity-Url/123456?v=app_555 => 45678
#    http://www.facebook.com/pages/Vanity-Url/45678 => 45678
#    http://www.facebook.com/#!/page_with_1_number => page_with_1_number
#    http://www.facebook.com/bounce_page#!/pages/Vanity-Url/45678 => 45678
#    http://www.facebook.com/bounce_page#!/my_page_id?v=app_166292090072334 => my_page_id

/(?:http:\/\/)?(?:www\.)?facebook\.com\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[\w\-]*\/)*([\w\-]*)/

To get the latest version: https://gist.github.com/733592


I'd recommend Rad Software Regular Expression Designer.

Also this online tool is great https://regex101.com/ ( though most people prefer http://regexr.com/ )

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