What is the specific implementation of the PHP regular expression match? In fact, we know that in the actual matching operation of the process we operate not only a single letter or number, then we face like a word or a set of numbers when the time to deal with it?
The specific implementations of the PHP regular expression match are used in the PHP regular expression built-in universal character clusters, all of which have PHP regular expressions built-in universal character sets?
PHP Regular expression built-in universal Character set and meaning:
- Any letter
- Any number
- Any letters and numbers
- Any whitespace character
- Any capital letter
- Any lowercase letters
- Any punctuation
Analysis of PHP Regular expression matching:
So far, you already know how to match a letter or number, but more likely, you might want to match a word or a group of numbers. A word consists of several letters, and a group of numbers has several singular parts. The curly braces ({}) following the character or character cluster are used to determine the number of occurrences of the preceding content.
PHP Regular expression character set and meaning used
- ^[a-za-z_]$ //All letters and underscores
- ^[[:alpha:]]{3}$ //All 3-letter words
- ^a$ //Letter A
- ^a{4}$ //aaaa
- ^a{2,4}$ //aa,aaa or AAAA
- ^a{1,3}$ //a,aa or AAA
- ^a{2,}$ //contains more than two a strings
- ^a{2,} //such as: Aardvark and Aaab, but not Apple
- a{2,} //such as: Baad and AAA, but Nantucket not
- t{2} //Two tabs
- . {2} //All two characters
These examples describe the three different uses of curly braces. A number, {x}, means "the preceding character or character cluster appears only x times"; A number plus a comma, {x,} means "x or more occurrences of the preceding content", and two comma-delimited numbers, {x, y} means "the preceding content appears at least x times, but not more than Y". We can extend the pattern to more words or numbers:
- All strings that contain more than one letter, number, or underscore
- All positive numbers.
- All the integers
The last example is not very well understood, is it? Let's see: With all starts with an optional minus sign (-{0,1}), followed by 0 or more digits ([0-9]{0,}), and an optional decimal point (. { 0,1}) followed by 0 or more numbers ([0-9]{0,}), and nothing else ($). Below you will know the simpler way to use it.
Special characters "?" is equal to {0,1}, and they all represent: "0 or 1 preceding content" or "previous content is optional". So just the example can be simplified to:
- ^-? [0-9] {0,}.? [0-9] {0,}$
The special characters "*" are equal to {0,}, and they all represent "0 or more of the preceding content." Finally, the character "+" is equal to {1,}, which means "1 or more preceding contents", so the above 4 examples can be written as:
- ^[a-za-z0-9_]+$
- All strings that contain more than one letter, number, or underscore
- All positive numbers.
- All the integers
Of course, this does not technically reduce the complexity of regular expressions, but it makes them easier to read.
A specific implementation of the PHP regular expression match is introduced to you and hopefully helps you understand and learn about specific implementations of PHP regular expression matching.
http://www.bkjia.com/PHPjc/446576.html www.bkjia.com true http://www.bkjia.com/PHPjc/446576.html techarticle What is the specific implementation of the PHP regular expression match? In fact, we know that in the actual matching operation of the process we operate not only a single letter or number, then we face ...