[ 
https://issues.apache.org/jira/browse/GROOVY-11701?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King resolved GROOVY-11701.
--------------------------------
    Fix Version/s: 5.0.0-beta-2
         Assignee: Paul King
       Resolution: Fixed

Proposed PR merged.

> Improved named-capturing group support for Groovy matchers
> ----------------------------------------------------------
>
>                 Key: GROOVY-11701
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11701
>             Project: Groovy
>          Issue Type: New Feature
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>             Fix For: 5.0.0-beta-2
>
>
> Java regex supports named-capturing groups which can still be accessed by 
> index. Groovy's shortcut syntax only supports the index access:
> {code:groovy}
> def regex = $/(?<day>\d{1,2})(?<sep>[-/])(?<month>\w{3})\k<sep>(?<year>\d+)/$
> def m = '25-DEC-2025' =~ regex
> assert m[0][1] == '25'
> assert m[0][2] == '-'
> assert m[0][3] == 'DEC'
> assert m[0][-1] == '2025'
> assert m.replaceAll('${month} ${day}, ${year}.') == 'DEC 25, 2025.'
> {code}
> This issue is to add named support in the normal Groovy way:
> {code:groovy}
> assert m[0].day == '25'
> assert m[0].sep == '-'
> assert m[0]['month'] == 'DEC'
> assert m[0]['year'] == '2025'
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to