Skip to content

add Index and LastIndex property to $matches variable #11755

Closed

Description

@p0W3RH311

steps to reproduce

PS C:\> 'hello' -match 'e'
True
PS C:\> $Matches | fl *

Name      : 0
Key       : 0
Value     : e
Index     : 1
LastIndex : 2

Activity

  1. added
    Issue-Enhancement
    on Feb 2, 2020
  2. vexx32 commented on Feb 2, 2020

    @vexx32
    Collaborator

    I'm not really sure what you're asking here. What purpose would this serve? $matches is just a hashtable; all it really has is key and value for each item.

    I'd also recommend you follow the feature suggestion template we have so that others can more easily understand what exactly it is that you're proposing 😊

  3. iSazonov commented on Feb 3, 2020

    @iSazonov
    Collaborator

    It is about first and last position of found substring in source line.

  4. vexx32 commented on Feb 3, 2020

    @vexx32
    Collaborator

    Ilya (@iSazonov) thanks, that makes a bit more sense! It does raise the question of whether we want First/LastIndex of just the 0 entry, though, or whether we'd want to add it for each match group entry as well?

  5. iSazonov commented on Feb 3, 2020

    @iSazonov
    Collaborator

    I guess it is based on Regex and we can not add the indexes without performance degradation.

  6. mklement0 commented on Feb 3, 2020

    @mklement0
    Contributor

    Adding new entries to $Matches is also a potentially breaking change.

    However, we discussed returning [System.Text.RegularExpressions.Match] instances in the context of a future -allmatches operator - #7867 - which would at least enable you to do:

    PS> ('hello' -allmatches 'e')[0]
    
    Groups   : {0}
    Success  : True
    Name     : 0
    Captures : {0}
    Index    : 1
    Length   : 1
    Value    : e
    
  7. iSazonov commented on Feb 4, 2020

    @iSazonov
    Collaborator

    Michael Klement (@mklement0) Can you move this in #7867 explicitly?

  8. mklement0 commented on Feb 4, 2020

    @mklement0
    Contributor

    Assuming you meant my previous comment, Ilya (@iSazonov): done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementResolution-Duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions