Regular Expressions 101

Community Patterns

Matching of temperatures (celsius, fahrenheit, and kelvin)

0

Regular Expression
PCRE (PHP <7.3)

/
(?P<amount>-?\d+(?:\.\d*)?)[^\S\n]*(?P<degrees>°|deg(?:rees?)?|in)?[^\S\n]*(?P<unit>c(?:(?=el[cs]ius\b|entigrades?\b|\b))|f(?:(?=ahrenheit\b|\b))|k(?:(?=elvins?\b|\b)))
/
gi

Description

Matches common types of English-written temperature units.

Submitted by anonymous - 7 years ago