只是为了得到这一点的方式,我会使用index,substr或类似的,因为他们是我的特殊情况下,显而易见的解决办法,但我正在做grammar,所以我只能用regex.:(
话虽如此,关于将Perl5/PCRE正则表达式转换为Perl6正则表达式的建议无论如何都是很好的SO内容,因为Perl 6越来越受欢迎,它的正则表达式引擎非常不同.
这是一个正则表达式,只匹配一个不包含任何给定字符列表的字符串.
(试试吧.)
^(?:(?!\/).)*$
^ # assert position at start of string
(?: # begin a noncapturing group
(?! # negative lookahead: following regex must not match the string
\/ # literal forward slash
) # end negative lookahead
. # any character, once
)* # the previous noncapturing group, 0..Inf times
$ # assert position at end of string
Run Code Online (Sandbox Code Playgroud)
显然,由于多种原因,在Perl 6中不起作用.
基于上述原因,我希望在Perl 6使用此这里就是我试图要翻译成的基础上,CTRL-F荷兰国际集团 …
我可以使用哪个正则表达式来查找所有字符串bar前面没有字符串foo?在两者之间有空格也是非法的.
所以正则表达式应匹配以下字符串
foo is bar
hello bar
Run Code Online (Sandbox Code Playgroud)
但不是这些
foobar
foo bar
Run Code Online (Sandbox Code Playgroud)
我尝试过使用以下内容
(?!<foo)bar
Run Code Online (Sandbox Code Playgroud)
它完成了消除工作foobar,但我需要照顾空白,当然
(?!<foo)\s*bar
Run Code Online (Sandbox Code Playgroud)
匹配所有字符串.
谢谢!