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·2016-03-03 15:30
Flavor·PCRE (Legacy)

/
^(?:N\d|N\d{2}|(?:EX|N|P|V8|XU)\d{3}|(?:B|CP|CU-T|HL|JA|JU|N|OB|OE|OK|RPC|V7|VN|YV)\d{4}|(?:4K|4L|B|EK|ER|EW|EX|EY|N|RA|RDPL|UK|UN|UR)\d{5}|RA\d{4}K|VN[A-Z]\d{3}|4K[A-Z]{2}\d{2}|(?:4L|UR)[A-Z]{3}|XC[A-Z]{3}\d{2}|(?:HJ|HK|N)\d{4}[A-Z]|HP\d{4}[A-Z]{3}|(?:JA|N|YV)\d{3}[A-Z]|(?:EW|HI|N)\d{3}[A-Z]{2}|N\d{2}[A-Z]|(?:JA|N)\d{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