Perl 6 分别捕获重复的匹配组? [英] Perl 6 capturing repeating matching groups separately?

查看:72
本文介绍了Perl 6 分别捕获重复的匹配组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信 Perl 6 提供了单独捕获重复组的能力,而不是早期的风格,您只能捕获最后一组或整个匹配的组字符串.有人可以举一个很好的例子来说明如何使用 Perl 6 的这个很棒的特性吗?例如

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

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

我如何在 Perl 6 中做到这一点?

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

也适用于位置捕获:

$ 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?

这篇关于Perl 6 分别捕获重复的匹配组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆