Community Patterns

1

Paragraph Delimiter Counter (Unicode-Aware)

Created·2024-12-05 02:56
Updated·2024-12-05 03:24
Flavor·.NET 7.0 (C#)
Finds all paragraphs in the input text, where a paragraph is defined as any occurrence of a non-whitespace character immediately following any of the following and any other preceding whitespace: 2 or more consecutive CRLF sequences 2 or more consecutive CR characters 2 or more consecutive LF characters 1 or more Unicode Paragraph Separator class characters The beginning of the string (matches the first paragraph) Again, note that whitespace mixed in with the above will not interfere with the matching, as demonstrated by the test text included. This is intended to be used with the options specified, so be sure to include them for best performance (non-backtracking, multiline, non-capturing, invariant culture). This will work effectively on any version of .net that supports the included syntax. However, it is intended for use with .net8.0 and up, with the Regex.EnumerateMatches() method, or, more ideally, with .net9.0 and up, using the new Regex.EnumerateSplits() method, to avoid allocations associated with Match objects. Unicode paragraph separator characters are very rare in practice and support for them is almost non-existent in software, including the Windows Console. Windows Terminal, web browsers, the Windows clipboard, notepad, Visual Studio, and notepad++, all of which fail to handle it in their own ways, none of them actually adding a line when they occur (though notepad++ will show it as PS if you have enabled showing all whitespace). It is safe to remove |\p{Zp}+ from the pattern, if you do not wish to include those characters in your search. The resulting pattern, as a c# string, would be: "((\\r\\n|\\r|\\n){2,}|\\A)^\\s*\\S"
Submitted by dodexahedron

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