Regular is used to handle strings in a text pattern that can match, find, replace, and split strings. Regular is composed of atoms (ordinary strings), some special meanings of characters, and delimiters, pattern modifiers.
The delimiter indicates that the regular expression has been written and is generally used/to represent.
Atoms are arbitrary characters, and different characters that are special to the regular need to be escaped before they can be used, such as. + * ?
Some provisions of the simplified special characters: \d matches any number, \d out numeric characters, \w numbers and letters, underscores \w \s any white space character
Yenzi:
* 0 times, one or more times
+ one or more times
? 0 or one time.
. Any character other than line breaks
| branch Selection
{N},{n,m}
^ or \a match start
$ or \z match end
\b Match word boundaries
\b does not match word boundaries
[]
[^]
()
Example:
Match this is test
Boundary limit:
/^this/matches the string at the beginning of this
/test$/match string at end of test
/\bis\b/matches the is character that has boundaries around it, only is matches
/\bis\b/matches a character with a border to the right with only this
Mode modifier:
I is case insensitive
M treats a string as multiple lines
s if set,. matches any character including line breaks
white space negative in x mode
U reverses the value of the matched quantity so that it is not the default repetition, unless it is repeated, or you can add one after the quantifier to make it non-repeating, such as. *?,{n}?, this modifier may be unique to PHP.
Example: if matching ABCDEFGABCDEFGABCDE
/a.*e/will match the entire string,/a.*?e/and/a.*e/u will match ABCDE,
/web server/x will be negative and can match webserver.
/^is/m matches the is test in This\nis test
Common matching rules:
Email
/\w+ ([-+.] \w) *@\w+ ([-.] \w) *\.\w+ ([-.] \w) */
Url:/^http[s]?:\ /\/([\w-]+\.) +[\w-]+ ([\w-./?%&=]*)? $/
English:/^[\u4e00-\u9fa5\uf900-\ufa2d]+$/
ASCII string: ^[\x00-\xff]+$
ip:/(25[0-5]|2[0-4]\d|1\d{2}|[ 1-9]?\d) \.25[0-5]|2[0-4]\d|1\d{2}| [1-9]?\d\.25[0-5]|2[0-4]\d|1\d{2}| [1-9]?\d\.25[0-5]|2[0-4]\d|1\d{2}| [1-9]?\d] */
PHP Regular: