Community Patterns

19

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·2023-06-19 17:38
Flavor·Java

"
\b((0?[1-9]|[12][0-9]|3[01])[-/.\s](0?[1-9]|1[0-2])[-/.\s](19[0-9]{2}|200[0-9]))|((0?[1-9]|1[0-2])[-/.\s](0?[1-9]|[12][0-9]|3[01])[-/.\s](19[0-9]{2}|200[0-9]))|(([012][1-9]|3[01])(st|nd|rd|th)?\s(?i:Jan|Feb|Fév|Mar|Apr|Avr|May|Mai|Jun|Juin|Jul|Juil|Aug|Sep|Sept|Oct|Nov|Dec|Déc)\s(?:19[0-9]{2}|200[0-9]))|((?i:Jan|Feb|Fév|Mar|Apr|Avr|May|Mai|Jun|Juin|Jul|Juil|Aug|Sep|Sept|Oct|Nov|Dec|Déc)\s(?:0?[1-9]|[12][0-9]|3[01])(st|nd|rd|th)?\s(?:19[0-9]{2}|200[0-9]))|((0?[1-9]|[12][0-9]|3[01])(st|nd|rd|th)?\s(?i:January|janvier|February|fevrier|février|March|mars|April|avril|May|mai|June|juin|July|juillet|August|aout|août|September|septembre|October|octobre|November|novembre|December|décembre|decembre)\s(?:19[0-9]{2}|200[0-9]))|((?iu:January|janvier|February|fevrier|février|March|mars|April|avril|May|mai|June|juin|July|juillet|August|aout|août|September|septembre|October|octobre|November|novembre|December|décembre|decembre)\s(?:0?[1-9]|[12][0-9]|3[01])(st|nd|rd|th)?\s(?:19[0-9]{2}|200[0-9]))|(0?[1-9]|1[0-2])[-\/.\s](0?[1-9]|[12][0-9]|3[01])[-\/.\s](19|20)0[0-9]|(19|20)0[0-9][-\/.\s](0?[1-9]|1[0-2])[-\/.\s](0?[1-9]|[12][0-9]|3[01])\b
"
gm
Open regex in editor

Description

Covering Dates starting from year 2009 and older in French and English

Some of the valid Dates format April 2nd 2008 April 2 2008 April 02 2008 2009-01-01 31-03-2009 03-31-2009 31 March 2009 March 31 2009 31 mars 2009 May 10th 1989 April 2nd 2008 2009.01.01 2009 1 31 31st december 2009 31 décembre 2009 31 Decembre 2009 2009/02/01 2009.01.01 2009 01 01 31 03 2009 12 31 2009

Submitted by Francois-Alexandre Valade-Casaubon