search
Homephp教程php手册php preg_match正则表达式函数实例,phppregmatch函数

php preg_match正则表达式函数实例,phppregmatch函数

正则表达式几乎在所有编程语言里面都会用到,本实例介绍php中正则表达式preg_match函数的应用。

preg_match() 函数用于进行正则表达式匹配,成功返回 1 ,否则返回 0 。
preg_match() 匹配成功一次后就会停止匹配,如果要实现全部结果的匹配,则需使用 preg_match_all() 函数。

语法:

preg_match (pattern , subject, matches)

 

参数 描述
pattern 正则表达式
subject 需要匹配检索的对象
matches 可选,存储匹配结果的数组


实例:
此实例匹配大写字母后面带有.和空格的字符串,只能匹配到J. ,因为preg_match() 匹配成功一次后就会停止匹配,后面不会再匹配了。
 

<?<span>php
</span><span>$str</span>="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."<span>;
</span><span>if</span>(<span>preg_match</span>("/[A-Z]. /",<span>$str</span>,<span>$matches</span><span>)){
    </span><span>print_r</span>(<span>$matches</span><span>);
}
</span>?>

输出结果:

<span>Array</span> ( [0] => J. ) 

 

原文地址:http://www.manongjc.com/article/52.html

相关阅读:

php正则表达式函数使用实例

php preg_match函数和php preg_match_al函数l实例,方法,例子

php preg_match_all()函数使用实例

php preg_match正则表达式函数实例

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version