PHP is a regular expression of basic grammar application learning.
^ Start
$ end
* Match 0 or more of zero or more
"ab*" matches strings A and 0 or more B-composed strings ("a" "AB" "ABB" "abbbbbb" etc)
+ Match one or more single or more
The "ab+" matches the string A and one or more B strings ("AB" "ABB" "abbbbbb" etc) and the difference is that the following must match a B
? Match 0 or a zero or one
"AB" matches 0 or one B ("a", "AB")
.*? Used to match a large string of strings that do not require a regular string, that is, do not need to match directly to the past.
Example:
"a?b+$" matches a string ("B" "AB" "BBBBB" "abbbbbbb") ending with one or 0 a plus more than one B
Of course, you can add the number of restricted characters to the curly braces in the back.
"Ab{2}" matches one a must follow two B, "ABB"
"Ab{2,}" matches the B after a a must be greater than or equal to 2 "ABB" "ABBB" "ABBBBB"
"ab{2,5}" matches a b behind a a from 2 to 5 "ABB" "ABBB" "abbbb" "ABBBBB"
But less than two B would not be so "ab{,2}" must be This "ab{0,2}"
So for
* Just know the equivalent of {0}
+ equivalent to {1,}
? Equivalent to {0,1}
() is to link some strings together to match the
"A (BC) *" is matched by a and then followed by 0 BC or more BC "a" "abc" "ABCBC" "ABCBCBC" etc
| This character is equivalent to an OR operation
"Hi|hello" matches a string containing hi or hello
"(B|CD) EF" matches a string containing BEF or cdef
"(a|c) *d" match contains "D" "Ad" "CD" "AaB" "CCD" "Aaaaaaad" "CCCCCCCD"
. can represent all the single characters
"A.[0-9]" can match an A and then follow a string and then the last number "Aj9" "a<8" in which the middle of any single character is possible.
"^. {3}$ "ASD" starting and ending with three single characters will not be matched as "KJL" with extra three single characters.
[] The symbol includes live content that matches only one single character
"[AB]" is just a single or a single B equivalent to "a|b"
"[A-Z]" is a match for 26 lowercase letters
"^[a-za-z]" matches a string beginning with a letter
"[0-9]%" is the match of a string containing the form x percent
", [a-za-z0-9]$] matches a comma followed by a number or letter-ending string", 0 "", a "etc
PHP Some of the commonly used alternative symbols
# # or//indicates the delimiter single/represents escape character
\s means something that matches the white space.
\d matches a numeric character
\w matches any word character that includes an underscore
Online Big God summed up the comparison of the whole grammar.
Click to open link