Regular Expressions 101

Community Patterns

21

Get path from any text

Created·2023-01-31 14:38
Updated·2023-07-23 20:17
Flavor·PCRE2 (PHP)
Recommended·
Get path (windows style) from any type of text (error message, e-mail corps ...), quoted or not. THIS IS THE SINGLE LINE VERSION ! If you want understand how it work or edit it, go https://regex101.com/r/7o2fyy Relative path are not supported The goal is to catch what "Look like" a path. See the limitations UNC path and prefix path like //./], [//?/] or [//./UNC/] are allowed some url path like [file:///C:/] or [file://] are allowed Catch path quoted with ["] and [']. But these quotes are include with the catch Quoted path is not concerned by limitations Limitations : (only unquoted path) [dot] and [space] is allowed, but not in a row [dot+space] or [space+dot at end of file name isn't catched INSIDE A NAME FILE (or last directory if it is a path to a directory) : [comma] is not supported (it stop the catch) after a first [dot], any [space] stop the catch after a [space], catch is stoped if next character is not a [letter], [digit] or [-] so, double [space] stop the catch Compatibility compatible PCRE, PCRE2 AutoHotkey : don't forget to escape "%" in "`%" /!\ Powershell and .Net /!\\ : this regex need some modification to be interpreted by powershell. You have to replace each (?&CapturGroupName) by \k. Use this powershell code to do this replacement : ` $powershellRegex = @' [Put here the regex to replace (?&CapturGroupName) with \k] '@ -replace '\(\?&(\w+)\)', '\k' ` This example code must return : [Put here the regex to replace \k with \k]
Submitted by nitrateag

Community Library Entry

0

Regular Expression
Created·2015-12-13 16:23
Flavor·PCRE (Legacy)

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

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&width=300&connections=4&stream=false&header=false&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