我一直认为你不能在零宽度断言中使用重复量词(Perl Compatible Regular Expressions [PCRE]).但是,最近我发现你可以在前瞻断言中使用它们.
所以我的问题是:
PCRE正则表达式引擎在使用零宽度外观搜索时如何工作,从而无法使用重复量词?
以下是R中PCRE的一个简单示例:
# Our string
x <- 'MaaabcccM'
## Does it contain a 'b', preceeded by an 'a' and followed by zero or more 'c',
## then an 'M'?
grepl( '(?<=a)b(?=c*M)' , x , perl=T )
# [1] TRUE
## Does it contain a 'b': (1) preceeded by an 'M' and then zero or more 'a' and
## (2) followed by zero or more 'c' then an 'M'?
grepl( '(?<=Ma*)b(?=c*M)' , x …Run Code Online (Sandbox Code Playgroud)