Use regular expression 1 in PHP and function 1) preg_match-for Regular Expression Matching. compatible with perl's regular syntax intpreg_match (string $ pattern, string $ subject [, array $ matches [, int $ flags] using regular expressions in PHP
1. Functions
1) preg_match-regular expression matching, compatible with perl's regular syntax
Int
Preg_match(String $ Pattern, String $ Subject[, Array $ Matches[, Int $ Flags])
-
After the flag PREG_OFFSET_CAPTURE is added, it becomes a reverse match.
2) intEreg(String$ Pattern, String$ String[, Array& $ Regs])
Note: preg_match function ratioEreg ()Fast.
3) preg_grep-returns the array unit that matches the pattern.
Array preg_grep (string $ pattern, array $ input [, int $ flags])
Preg_grep () returns an array containing the units in the input array that match the given pattern.
Add the flag PREG_GREP_INVERT to reverse match.
(In the regular expression syntax ?! Peer)
For example
$ Subject = "4 | 43 | WINWORD. EXE | C: \ E ~ 1 \ iloveyou \ LOCALS ~ 1 \ Temp \~ DF39E9. tmp | EEWS | 1300763364 | ";
$ Pattern = '/\.(?! EXE | tmp). {3 }/';
Preg_match ($ pattern, $ subject, $ matches );
Print_r ($ matches );
?>
2. how to make the regular expression case insensitive
SQL _regcase-generate a regular expression for matching with no size difference
$ Fl_array = preg_grep (SQL _regcase ("/^ (ASSZs)/"), $ array );
3. how to filter file names by file suffix
$ Logs = preg_grep (SQL _regcase ('/^ .*? \. (Tmp | ini | pip ).*? /'), $ Logstring, PREG_GREP_INVERT );
The file name with the suffix tmp | ini | txt is filtered out and case-insensitive.
Blog from dongzige