Php preg_match Regular Expression Function instance, phppregmatch Function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.