Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

/
(?<lhs>(?:[\+\-]*)?\d+) *(?<op>[\+\-\*\/\^]) *(?<rhs>(?:[\+\-] *)?\d+)
/
gm

Description

Detect operations between integers (12^-3) and split them into three capture groups:

lhs: 12
op : ^ 
rhs: -3
Submitted by benetsugarboy - 3 months ago