PHP Tutorial Regular Expression Examples detailed (for beginners)
Mathematical formula Regular Expression:
(?' KH ' () * ([-+]) {0,1}[0-9.] +(?' -kh ')) * ([+-*/]{1} (?) KH ' () * ((? <= () ([-+]) {0,1})? [ 0-9.]+ (? ') -kh ')) + (? Kh ') (?!))
Matching subtraction mathematical formulas, such as: ((1+2) -3*4)
(?' KH ' () * ([-+]) {0,1}[0-9.] +(?' -kh ')) * ([+-*/]{1} (?) KH ' () * ((? <= () ([-+]) {0,1})? [ 0-9.]+ (? ') -kh ')) + (? Kh ') (?!))
Can "(" Start, press into stack count bracket number, * representative can appear 0 or more times
(?' KH ' () * ([-+]) {0,1}[0-9.] +(?' -kh ')) * ([+-*/]{1} (?) KH ' () * ((? <= () ([-+]) {0,1})? [ 0-9.]+ (? ') -kh ')) + (? Kh ') (?!))
You can have a positive sign
(?' KH ' () * ([-+]) {0,1}[0-9.] +(?' -kh ')) * ([+-*/]{1} (?) KH ' () * ((? <= () ([-+]) {0,1})? [ 0-9.]+ (? ') -kh ')) + (? Kh ') (?!))
0-9 digits, one or more
(?' KH ' () * ([-+]) {0,1}[0-9.] +(?' -kh ')) * ([+-*/]{1} (?) KH ' () * ((? <= () ([-+]) {0,1})? [ 0-9.]+ (? ') -kh ')) + (? Kh ') (?!))
Can "") End, pop-up stack count bracket number, * representative can appear 0 or more times
(?' KH ' () * ([-+]) {0,1}[0-9.] +(?' -kh ')) * ([+-*/]{1} (?) KH ' () * ((? <= () ([-+]) {0,1})? [ 0-9.]+ (? ') -kh ')) + (? Kh ') (?!))
Orange Bracket Group description can occur one or more times, such as formula 1+2, this bracket is a match 2
Red requires +-*/to appear once
(?' KH ' () * ([-+]) {0,1}[0-9.] +(?' -kh ')) * ([+-*/]{1} (?) KH ' () * ((? <= () ([-+]) {0,1})? [ 0-9.]+ (? ') -kh ')) + (? Kh ') (?!))
Do you have a positive or negative sign at the beginning of the bracket? Represents the use of lazy matching, such as: 1+ ((((2-3) +4) +5), only match the number 2 before the parentheses once
(?' KH ' () * ([-+]) {0,1}[0-9.] +(?' -kh ')) * ([+-*/]{1} (?) KH ' () * ((? <= () ([-+]) {0,1})? [ 0-9.]+ (? ') -kh ')) + (? Kh ') (?!))
Check that parentheses are paired