PHP Regular Expression example detailed (for beginners)

Source: Internet
Author: User
Tags php regular expression php tutorial regular expression

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.