php – 从正则表达式中获取不区分大小写的单词
发布时间:2020-12-13 16:51:41 所属栏目:PHP教程 来源:网络整理
导读:假设,我有一个字符串 $res = "there are many restaurants in the city. Restaurants like xyz,abc. one restaurant like....."; 在上面的例子中,我们可以在3个地方找到餐厅.我需要数到3. $pattern = '/Restaurant/';preg_match($pattern,substr($res,10),$m
假设,我有一个字符串
$res = "there are many restaurants in the city. Restaurants like xyz,abc. one restaurant like....."; 在上面的例子中,我们可以在3个地方找到餐厅.我需要数到3. $pattern = '/Restaurant/'; preg_match($pattern,substr($res,10),$matches,PREG_OFFSET_CAPTURE); print_r($matches); 还有一个问题 解决方法
你可以使用这样的正则表达式:
$pattern = '/restaurants?/i'; 我对原始正则表达式进行了两处更改: >添加i修饰符 – 这是不区分大小写的标志. 请注意,因为我们使用不区分大小写的标志,所以此正则表达式还将匹配以下内容: > ResTaurants> rEstaurantS> RESTauRANTS (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |