PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

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

原创
2016-06-13 08:43:16 1168浏览

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() 匹配成功一次后就会停止匹配,后面不会再匹配了。

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

输出结果:

Array ( [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正则表达式函数实例

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。