문제

I believe Perl 6 offers the capability of capturing repeating groups separately as opposed to earlier flavors where you could only capture the last group or the whole matched group string. Can someone please give a good example how to use this awesome feature of Perl 6? For e.g.

I need to capture all the matching groups for this regex

((?:(?:(?:(?:")(?:[^"]*?)")|(?:(?<!")(?:[^"]*?)(?!")))(?<!\\)\|)*) 

How do I do that in Perl 6?

도움이 되었습니까?

해결책

In general, if you quantify a capture, you simply get a list of all matches. Example:

$ perl6 -e '"abc" ~~ /<alpha>+/ and say $<alpha>.join(", ")'
a, b, c

works with positional captures too:

$ perl6 -e '"abc" ~~ /(\w)+/ and say $0.join(", ")'
a, b, c

Now you can just apply that to your own regex, which looks artificially convoluted. Is it generated in some way?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top