PHP 正则表达式preg_match

简化定义

preg_match (string $pattern , string $subject [array &$matches] ) : int

说明:
$pattern 搜索模式
$subject 字符串
$matches 搜索结果(可选)

界定符:/

示例

// 只校验结果
echo preg_match('/\d+/', '1234');
// 1


// 获取匹配结果
if(preg_match('/age=(\d+)/', 'age=16', $matches)){
    var_dump($matches);
}
/**
array(2) {
    [0]=> string(6) "age=16"
    [1]=> string(2) "16"
  }
*/

参考
PHP 正则表达式
https://www.php.net/manual/zh/function.preg-match.php

发布了1399 篇原创文章 · 获赞 355 · 访问量 127万+

猜你喜欢

转载自blog.csdn.net/mouday/article/details/104181957
今日推荐