PHP preg_match regular expression function example

WBOY
Release: 2016-07-29 08:55:25
Original
1220 people have browsed it

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, returning 1 successfully, otherwise returning 0.
preg_match() will stop matching after one successful match. If you want to match all results, you need to use the preg_match_all() function.

Syntax:

preg_match (pattern, subject, matches)
Parameters Description
pattern regular expression
subject needs to match the search Object
matches Optional, an array that stores matching results


Instance:
This instance matches strings with capital letters followed by . and spaces, and can only match J., because preg_match( ) will stop matching after one successful match, and will not match again.

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); } ?>
Copy after login

Output result:

Array ( [0] => J. )
Copy after login

Original address: http://www.manongjc.com/article/52.html

Related reading:

php regular expression function usage example

php preg_match Functions and php preg_match_al function l examples, methods, examples

php preg_match_all() function usage examples

php preg_match regular expression function examples

The above introduces the php preg_match regular expression function example, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!