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·2019-07-02 20:35
Flavor·Python

r"
[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?
"
gm
Open regex in editor

Description

Process:

  1. Temperature/ pressure data generated by CFD software StarCCM+
  2. Temperature/ pressure data extracted during runtime by StarCCM+ in form of *.csv files
  3. Data extracted every x timesteps (x = integer value >= 1)
  4. Data mapping performed using "tabular data mapper" tool in StarCCM+. Algorithm used = least squares. This step is automated by using java. Care must be taken to select correct X, Y, Z label (use "SavedCoord [X]", "SavedCoord [Y]", "SavedCoord [Z]" if CFD simulation is transient AND has rotation/ translation/ morphing. Use "X", "Y", "Z" label otherwise)
  5. Mapping produces .png file and depending on input file extension (.inp/ *.dat/ *.nas/ *.bdf) produces data in corresponding output file extension. File name of mapped data is same as the input file name (with extension *.inp/ *.dat/ *.nas/ *.bdf) used for mapping - word MAPPED and file name of *.csv file used to map data is appended to the file name of the mapped data file.

Input file name = FOR_MAPPING_PRESSURE_toWettedTankSurface_shellElements_NASTRAN_noRenumberingPerformed.dat MAPPED file name = MAPPED_FOR_MAPPING_PRESSURE_toWettedTankSurface_shellElements_NASTRAN_noRenumberingPerformed_using_tankSloshing_forNVH_xyzInternal_Table_2.400000e-01.dat

Temperature mapping using *.inp file and *.csv file produces data whose format looks like 8243965,81.8897 8243965,-18.2857

Pressure mapping using *.inp file and *.csv file produces data whose format looks like 177842,P,-100588 177842,P,912598

Pressure mapping using *.dat/ *.nas/ *.bdf file and *.csv file produces data whose format looks like PLOAD4,105,5686,1.091300E+05,,,,, PLOAD4,105,5686,-1.912900E+05,,,,,

Keywords like "*DLOAD" and "TEMPERATURE" are ignored. This regular expression is able to extract the nodal number and the data (temperature/ pressure) value (positive or negative): [-+]?(\d+(.\d)?|.\d+)([eE][-+]?\d+)?

Submitted by anonymous