只是爲了得到這一點的方式,我會使用index
,substr
或相似的,因爲他們是我的特殊情況下,顯而易見的解決辦法,但我正在做一個grammar
,所以我只能用regex
。 :(如何將此Perl5/PCRE轉換爲Perl 6正則表達式?
話雖這麼說,在翻譯Perl5中/ PCRE正則表達式來Perl6正則表達式的建議是很好,所以內容反正,因爲Perl 6的日益普及,它的正則表達式引擎是非常不同的。
Here's a regex to only match a string which doesn't contain any of a given list of characters.
(try it here)
^(?:(?!\/).)*$
^ # 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
顯然,並不在Perl 6的許多原因工作。
至於原因如上所述,我想在Perl 6使用這個下面就是我試圖把它翻譯成的基礎上,CTRL-F爲non capturing
和negative lookahead
荷蘭國際集團the perl6 regex docs:
[ \/ <!before .*> \/ <!after .*> || .? ]*
和故障(我認爲):
[ # begin a noncapturing group which apparently look like a charclass in p6
\/ # a literal forward slash
<!before .*> # negative lookahead for the immediately preceding regex (literal /)
\/ # a literal/
<!after .*> # negative lookbehind for the immediately preceding regex
|| .? # force this to be a noncapturing group, not a charclass
]* # end noncapturing group and allow it to match 0..Inf times
我實現這個像my regex not-in { ... }
,然後使用它像/^<not-in>$/
。但是,它返回Nil
爲每字符串,這意味着它不能正常工作。
我一直沒能找到http://regex101.com相當於對Perl 6,這樣玩弄它並不容易,因爲它是用Perl 5
如何翻譯這Perl 6的?
@ChristopherBottoms我做了,但我不知道什麼相關性對任何事情 – cat
'/^not-in $ /'應該是'/^ $ /'。 –
CIAvash
@CIAvash當然它應該!我很累,很抱歉。 – cat