How do I access the captures within a match?

前端 未结 2 1422
梦谈多话
梦谈多话 2021-01-20 11:35

I am trying to parse a csv file, and I am trying to access names regex in proto regex in Perl6. It turns out to be Nil. What is the proper way to do it?

gra         


        
2条回答
  •  生来不讨喜
    2021-01-20 12:18

    The match for lives within the scope of the capture group, which you get via $m1[0].

    As the group is quantified with *, the results will again be a list, ie you need another indexing operation to get at a match object, eg $m1[0][0] for the first one.

    The named capture can then be accessed by name, eg $m1[0][0]. This will already contain the match result of the appropriate branch of the protoregex.

    If you want the whole list of matches instead of a specific one, you can use >> or map, eg $m1[0]>>..

提交回复
热议问题