Home > Web Front-end > JS Tutorial > body text

How to match Abba's reverse lookahead with regular expressions

php中世界最好的语言
Release: 2018-03-30 14:07:01
Original
2126 people have browsed it

这次给大家带来正则怎么匹配Abba逆向前瞻,正则匹配Abba逆向前瞻的注意事项有哪些,下面就是实战案例,一起来看一下。

核心代码:

Copy after login

零宽断言(?!exp)

反先行断言

什么是反先行断言,使用 (?!exp) 匹配后面跟的不是exp。

php实例:

主要是想通过实例给大家说下这个正则的作用

$str="abcgwcab";
$parent='/bc(?!ww)gw/';
$str=preg_match($parent,$str,$match);
var_dump($str);
var_dump($match);
/**
输出:
int 1
array (size=1)
 0 => string 'bcgw' (length=4)
*/
Copy after login

解析:首先判断字符串是否包含bc,然后判断其后面不是ww,最后匹配gw。可以看出反向断言之前后之后,能够在添加其他匹配条件。

.*?

这个.*就是匹配非空字符任意长度,?就是非贪婪模式就是匹配最少的字符例如一个字符

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

正则全局匹配模式g修饰符的使用详解

正则表达式m修饰符(多行匹配)使用详解

The above is the detailed content of How to match Abba's reverse lookahead with regular expressions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!