Regular Expressions 101

Community Patterns

Facebook Page/Profile. No profile.php. No /groups/

0

Regular Expression
PCRE (PHP <7.3)

/
(?:https?:\/\/)?(?:www\.)?facebook\.com\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[\w\-]*\/)*?(\/)?([\w\-\.]{5,})
/
ig

Description

Example:

http://www.facebook.com/profile.php?id=123456789 http://www.facebook.com/someusername https://www.facebook.com/0x20.be http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2F2leep%2F109473355777935&amp;width=300&amp;connections=4&amp;stream=false&amp;header=false&amp;height=250

Matches patterns such as:

https://www.facebook.com/my_page_id => my_page_id

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 => 123456

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/my.page.is.great => my.page.is.great

https://www.facebook.com/Babies.Fan.Page https://www.facebook.com/pages/Babies.Fan.Page/121166161229757

https://www.facebook.com/pages/GHOST-Caf%C3%A9/627191887397533?fref=ts

decoded: /like.php?href=http://www.facebook.com/#!/pages/Schenectady-NY/1045-The-Team-ESPN-Radio/100568296308&amp;width&amp;layout=button&amp;action=like&amp;show_faces=false& amp;share=false&height=35" scrolling="no" frameborder="0" style="overflow:hidden; width:50px; height:20px;" allowTransparency="true"></iframe>-->

decoded: /like.php?href=http://drupal7.arisiahosting.org&amp;send=false&amp;layout=standard&amp;width=230&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=l ucida+grande&height=35" style="border:none; overflow:hidden; width:230px; height:35px;"></iframe></p>

    <a   class="facebook share_link" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2F1045theteam.com%2Fmelo-to-knicks-but-who-called-shots%2F%3Ftrackback%3Dfbshare

&t=Melo+To+Knicks+But+Who+Called+Shots%3F" title="Share on Facebook" target="_blank">

	<li><a target="_blank" href="https://www.facebook.com/groups/82338447841/">14ers.com on Facebook<img src="/images/icon_globe_extratiny.png" class="picglobe"></a></li>
Submitted by aramosf - 8 years ago