Php preg_match Regular Expression Function instance, phppregmatch Function
Regular expressions are used in almost all programming languages. This example introduces the application of the regular expression preg_match function in php.
The preg_match () function is used for regular expression matching. If the regular expression matches successfully, 1 is returned. Otherwise, 0 is returned.
After a successful preg_match () match, the match is stopped. to match all the results, use the preg_match_all () function.
Syntax:
| Preg_match (pattern, subject, matches) |
| Parameters |
Description |
| Pattern |
Regular Expression |
| Subject |
Objects to be retrieved |
| Matches |
(Optional) array of matching results |
Instance:
This instance matches strings with. And spaces after uppercase letters, and can only match J., because after a successful preg_match () match, the match will be stopped and will not be matched later.
<?php$str="Daniel J. Gross Catholic High School A. is a faith and family based community committed to developing Christian leaders through educational excellence in the Marianist tradition.";if(preg_match("/[A-Z]. /",$str,$matches)){ print_r($matches);}?>
Output result:
Array ( [0] => J. )
Address: http://www.manongjc.com/article/52.html
Related reading:
Php Regular Expression Function example
Php preg_match function and php preg_match_al function l instance, method, Example
Php preg_match_all () function instance
Php preg_match Regular Expression Function instance