What does the/(. *)/isU and "isU" parameter after the regular expression mean?
This is the modifier in the regular expression.
I is used to search for uppercase and lowercase letters at the same time,
S indicates that the dot (.) matches all characters, including line breaks. If s is not set, the line breaks are not included.
U reverses the value of the matching quantity so that it is not the default repetition, but becomes behind "?" To be repeated.
Example
In the regular expression syntax compatible with preg_match, B represents the word boundary.
So: which of the following is OK ???
The code is as follows: |
Copy code |
$ A = "test, admin, abc "; $ B = "te "; $ Exist = preg_match ("/B {$ B} B/", $ ); If ($ exist) { Echo "exists "; } Else { Echo "does not exist "; } |
Take a look at the relevant instructions
Int preg_match (string pattern, string subject [, array matches [, int flags]);
Preg_match () returns the number of times pattern matches. Either 0 (no match) or 1 time, because preg_match () will stop searching after the first match. Preg_match_all () indicates that, on the contrary, the end of the subject is always searched. If an error occurs in preg_match (), false is returned.
Example:
The code is as follows: |
Copy code |
<? Php $ A = "abcdefgabcdefaaag "; Preg_match ('| abc ([a-z] +) g | isu', $ a, $ out1 ); Preg_match_all ('| abc ([s] +) g | isu', $ a, $ out2 ); Echo "<pre> "; Print_r ($ out1 ); Print_r ($ out2 ); Echo "</pre> "; ?> |
Statement:
When double quotation marks are used, they are different from single quotation marks.
The code is as follows: |
Copy code |
<? Php Preg_match_all ("/href =" (. *) "/isu", $ contents, $ out ); Preg_match_all ('| href = "(. *)" | isu', $ contents, $ out ); ?> |