Php Regular Expression example (suitable for beginners)-PHP source code

Source: Internet
Author: User
Tags php regular expression
Ec (2); php tutorial Regular Expression examples (suitable for beginners) mathematical formula Regular Expressions :(? Kh () * ([-+]) {0, 1} [0-9.] + (? -Kh) * ([+-*] {1 }(? Kh ()*((? & Lt; () ([-+]) {0, 1 })? [0-9.] + (? -Kh) *) + (? (Kh )(?!)) Match the mathematical formula of addition, subtraction, multiplication, division, for example: (1 + 2)-3*4 )(? Kh () * ([-+]) {0, script ec (2); script

Php tutorial Regular Expression examples (suitable for beginners)
Regular Expressions of mathematical formulas:
(? 'Kh' () * ([-+]) {0, 1} [0-9.] + (? '-Kh') * ([+-*/] {1 }(? 'Kh '()*((? <= () ([-+]) {0, 1 })? [0-9.] + (? '-Kh') *) + (? ('Kh ')(?!))

Match the mathematical formula of addition, subtraction, multiplication, division, for example: (1 + 2)-3*4)

(? 'Kh' () * ([-+]) {0, 1} [0-9.] + (? '-Kh') * ([+-*/] {1 }(? 'Kh '()*((? <= () ([-+]) {0, 1 })? [0-9.] + (? '-Kh') *) + (? ('Kh ')(?!))
Yes. ("START, press into the stack to count the number of parentheses. * indicates that the number of braces can appear 0 or multiple times.

(? 'Kh' () * ([-+]) {0, 1} [0-9.] + (? '-Kh') * ([+-*/] {1 }(? 'Kh '()*((? <= () ([-+]) {0, 1 })? [0-9.] + (? '-Kh') *) + (? ('Kh ')(?!))
A positive or negative sign can appear.

(? '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 be ")" ended. The number of statistical parentheses in the stack is displayed. * indicates that the number of statistical parentheses can appear 0 or multiple times.

(? 'Kh' () * ([-+]) {0, 1} [0-9.] + (? '-Kh') * ([+-*/] {1 }(? 'Kh '()*((? <= () ([-+]) {0, 1 })? [0-9.] + (? '-Kh') *) + (? ('Kh ')(?!))
The orange brackets can be grouped once or multiple times. For example, if the formula is 1 + 2, the brackets match 2.
Red requirement +-*/appears once

(? 'Kh' () * ([-+]) {0, 1} [0-9.] + (? '-Kh') * ([+-*/] {1 }(? 'Kh '()*((? <= () ([-+]) {0, 1 })? [0-9.] + (? '-Kh') *) + (? ('Kh ')(?!))
When the brackets start to be judged, there can be positive and negative signs ,? It indicates that when a slot match is used, for example, 1 + (2-3) + 4) + 5), only one bracket before the number 2 is matched.

(? 'Kh' () * ([-+]) {0, 1} [0-9.] + (? '-Kh') * ([+-*/] {1 }(? 'Kh '()*((? <= () ([-+]) {0, 1 })? [0-9.] + (? '-Kh') *) + (? ('Kh ')(?!))
Check whether 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.