Regular Expressions 101

Community Patterns

22

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

1

Regular Expression
Created·2020-08-13 18:28
Flavor·PCRE (Legacy)

/
(S3C|S2C|S1C|PO3|PO2|PO1|CPO|SCPO|MCPO|SMCPO|ENS|LTJG|LTSG|LT|LCDR|CAPTJG|CAPTSG|CDR|CDRE|CDRE\(F\)|RADM|VADM|ADM|FADM|AotF|Bosun|BT3|BT2|BT1|BM3|BM2|BM1|CBM|SCBM|MCBM|SMCBM|MAA3|MAA2|MAA1|MAM3|MAM2|MAM1|CMAA|SCMAA|MCMAA|SMCMAA|OPS3|OPS2|OPS1|OPM3|OPM2|OPM1|COPM|SCOPM|MCOPM|SMCOPM|INS3|INS2|INS1|INM3|INM2|INM1|CINM|SCINM|MCINM|SMCINM|PN3|PN2|PN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