PHP preg_match Regular Expression function instance, Phppregmatch function _php Tutorial

Source: Internet
Author: User

PHP preg_match Regular Expression function instance, Phppregmatch function


Regular expressions are used in almost all programming languages, and this example introduces the application of the Preg_match function of the normal expression in PHP.

The Preg_match () function is used to match a regular expression, successfully returning 1, otherwise returning 0.
Preg_match () will stop the match once the match is successful, and if you want to match all results, use the Preg_match_all () function.

Grammar:

Preg_match (pattern, subject, matches)

Parameters Describe
Pattern Regular expressions
Subject Objects that need to be matched for retrieval
Matches Optional, storing an array of matching results


Instance:
This instance matches a string with a. And a space followed by an uppercase letter and can only match to J. Because the Preg_match () match will stop the match once, and no longer match.

 
  php$str= "Daniel J. Gross Catholic High School A. are a faith and family based community committed to developing CH Ristian leaders through educational excellence in the Marianist tradition. " ; if (preg_match("/[a-z"). /",$str,$matches)) {    print_r($matches);}? >

Output Result:

Array

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

Related reading:

PHP Regular Expression function usage instance

PHP preg_match functions and PHP Preg_match_al functions L instances, methods, examples

PHP Preg_match_all () function Use instance

PHP preg_match Regular Expression function instance

http://www.bkjia.com/PHPjc/1115243.html www.bkjia.com true http://www.bkjia.com/PHPjc/1115243.html techarticle PHP preg_match Regular Expression function instance, Phppregmatch function regular expression in almost all programming languages will be used, this example introduces the PHP expression Preg_match function should be ...

  • 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.