Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

/
(?<![\p{Pd}\x{2212}\w])(?<number>[\p{Pd}\x{2212}]?\d+|\d+\.|\d+\.\d+|\.\d+)\p{Zs}*(?<unit>%|(?:[Mkdcm]?bar|mmHg|ha|min|\xC5)|(?:(?:[KMGTPEZY]i)?(?:bit|[bB]))|m?Np|(?:(?:da|[YZEPTGMkhdcm\x{03bc}npfazy])?(?:Wb|Sv|Hz|sr|mol|lm|lx|cd|rad|Pa|Bq|Da|eV|ua|Gy|kat|°C|[gmsulAKNJWCVFSTHL\x{03a9}]))|dB(?:FS|iC|m0s?|mV|ov|pp|rnC|sm|TP|\x{03bc}V|\x{03bc}0s|VU| HL| Q| SIL| SPL| SWL|\/K|-Hz|[ABcCdefGiJkKmoOqruvVWZ\x{03bc}])?|[hdta])(?:(?:\p{Zs}*\+(?<pos_tolerance>\d+|\d+\.|\d+\.\d+|\.\d+)\p{Zs}*(?<pos_unit>%|(?:[Mkdcm]?bar|mmHg|ha|min|\xC5)|(?:(?:[KMGTPEZY]i)?(?:bit|[bB]))|m?Np|(?:(?:da|[YZEPTGMkhdcm\x{03bc}npfazy])?(?:Wb|Sv|Hz|sr|mol|lm|lx|cd|rad|Pa|Bq|Da|eV|ua|Gy|kat|°C|[gmsulAKNJWCVFSTHL\x{03a9}]))|dB(?:FS|iC|m0s?|mV|ov|pp|rnC|sm|TP|\x{03bc}V|\x{03bc}0s|VU| HL| Q| SIL| SPL| SWL|\/K|-Hz|[ABcCdefGiJkKmoOqruvVWZ\x{03bc}])?|[hdta])?\p{Zs}*\/\p{Zs}*[\p{Pd}\x{2212}](?<neg_tolerance>\d+|\d+\.|\d+\.\d+|\.\d+)\p{Zs}*(?<neg_unit>%|(?:[Mkdcm]?bar|mmHg|ha|min|\xC5)|(?:(?:[KMGTPEZY]i)?(?:bit|[bB]))|m?Np|(?:(?:da|[YZEPTGMkhdcm\x{03bc}npfazy])?(?:Wb|Sv|Hz|sr|mol|lm|lx|cd|rad|Pa|Bq|Da|eV|ua|Gy|kat|°C|[gmsulAKNJWCVFSTHL\x{03a9}]))|dB(?:FS|iC|m0s?|mV|ov|pp|rnC|sm|TP|\x{03bc}V|\x{03bc}0s|VU| HL| Q| SIL| SPL| SWL|\/K|-Hz|[ABcCdefGiJkKmoOqruvVWZ\x{03bc}])?|[hdta]))|(?:\p{Zs}*±\p{Zs}*(?<tolerance>\d+|\d+\.|\d+\.\d+|\.\d+)\p{Zs}*(?<tolerance_unit>%|(?:[Mkdcm]?bar|mmHg|ha|min|\xC5)|(?:(?:[KMGTPEZY]i)?(?:bit|[bB]))|m?Np|(?:(?:da|[YZEPTGMkhdcm\x{03bc}npfazy])?(?:Wb|Sv|Hz|sr|mol|lm|lx|cd|rad|Pa|Bq|Da|eV|ua|Gy|kat|°C|[gmsulAKNJWCVFSTHL\x{03a9}]))|dB(?:FS|iC|m0s?|mV|ov|pp|rnC|sm|TP|\x{03bc}V|\x{03bc}0s|VU| HL| Q| SIL| SPL| SWL|\/K|-Hz|[ABcCdefGiJkKmoOqruvVWZ\x{03bc}])?|[hdta])))?(?![\p{Pd}\x{2212}\w])
/
gm

Description

This regular expression matches a quantity and tolerances, if they exist.

Submitted by nessalc - 3 years ago (Last modified 3 years ago)