Skip to content

Support for matching a pattern repeatedly on the same line #69

Open

Description

@harro

Breaking out from issue #18, with pull request #38

Activity

  1. itdependsnetworks commented on Nov 16, 2019

    @itdependsnetworks

    If breaking out, it would be great to get your interpretation of the potential solution. Hard for an outside reader to decompose based on title and reference alone.

  2. gachteme commented on Nov 18, 2019

    @gachteme

    support for capture of multiple matches per field per line.

    example text to match:
    key1:val1, key2:val2, key3:val3 ...
    where the number of times this is repeated is arbitrary.

    You would think to go about a match as so:

    Value keys (\S+)
    Value vals (\S+)
    
    Start
      ^({keys}:{vals},\s?)+
    

    but python re does not support this and would only give you key3 and val3.

    Pull request adds a dependency to a different regex parsing module which has this functionality and is backwards compatible with re. Other solutions would include post processing (some functionality could be lost), or making repeated matches very general then going through the general match recursively as you strip layers of parenthesis, which would be ugly to implement.

    There are examples and test cases in #38 if you want to see the functionality of some edge cases.

  3. changed the title [-]Repeat option support[/-] [+]Support for matching a pattern repeatedly on the same line[/+] on Nov 26, 2019
  4. boniek83 commented on Mar 9, 2020

    @boniek83

    This is useful. Are you guys planning on merging this anytime soon?

  5. DanSheps commented on Sep 29, 2021

    @DanSheps

    Has there been any movement on this at all?

  6. giovanni-bellini-argo commented on Jun 21, 2024

    @giovanni-bellini-argo

    👀 still in future plans?

  7. harro commented on Oct 4, 2024

    @harro
    CollaboratorAuthor

    It's been a while but IIRC the blocker for this is template compatibility. As alternate implementations, such as golang (#64) uses a different regexp engine (or at least they did).

    So if the python instance supports regexp functionality that is not a common denominator across implementations then the template libraries would need to be split, as different templates would be required depending on the textfsm instance.

  8. giovanni-bellini-argo commented on Oct 4, 2024

    @giovanni-bellini-argo

    As far as i can see the go implementation linked in the discussion isn't maintained, wouldn't there be more gains in mergin this?

  9. harro commented on Nov 28, 2024

    @harro
    CollaboratorAuthor

    Adding this would preclude using a common template library across implementations, not just the golang implementation above but any implementation (now or in future) that uses this different regexp implementation.

  10. harro commented on Jan 8, 2025

    @harro
    CollaboratorAuthor

    My inclination is to close this as 'working as intended', as in, we implement a widely supported set of regexp behaviours per the POSIX extended regular expressions standard: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html

    If there's a way to meet this feature request within this POSIX standard then we should definitely do it! Otherwise probably not unless popular alternate languages, like golang, rust etc converge on supporting the same (extended)ERE behaviour similar to the library suggested for Python.

    The final call on this would probably be up to @itdependsnetworks as he maintains the template libraries, and would be most impacted by this change?

  11. itdependsnetworks commented on Jan 8, 2025

    @itdependsnetworks
  12. DanSheps commented on Jan 9, 2025

    @DanSheps

    If there's a way to meet this feature request within this POSIX standard then we should definitely do it! Otherwise probably not unless popular alternate languages, like golang, rust etc converge on supporting the same (extended)ERE behaviour similar to the library suggested for Python.

    I don't think there is a need for a new library. Not sure why this can't be done in the existing RE engine (haven't looked at the PR that much TBH however). You would have to use python's finditer instead of match but I think it is doable. Might not be quite that simple but should be pretty close. I don't think Repeatable needs to do anything on the line itself (like actually do the repeating, just that the keyword should enable repeating) because there may be additional things people want to do, ex:

    2062 VLAN2062      active    Gi1/0/1, Gi1/0/3, Gi1/0/6, Gi1/0/8, Gi1/0/9, Gi1/0/10, Gi1/0/11, Gi1/0/12, Gi1/0/13, Gi1/0/15, Gi1/0/16, Gi1/0/17, Gi1/0/18, Gi1/0/19
                                                    Gi1/0/20, Gi1/0/21, Gi1/0/22, Gi1/0/23, Gi1/0/24, Gi1/0/25, Gi1/0/26, Gi1/0/27, Gi1/0/28, Gi1/0/29, Gi1/0/30, Gi1/0/31, Gi1/0/32, Gi1/0/33
                                                    Gi1/0/34, Gi1/0/35, Gi1/0/36, Gi1/0/37, Gi1/0/38, Gi1/0/39, Gi1/0/40, Gi1/0/42, Gi1/0/44, Gi1/0/46, Gi1/0/48, Gi2/0/1, Gi2/0/3, Gi3/0/2
                                                    Gi3/0/4
    
    
    Value Key VID (\d+)
    Value Key Name (\S+)
    Value Repeatable,List INTERFACES (Gi\d/\d/\d+)
    
    Start
        ^\d+ -> Continue.Record
        ^${VID}\s+${Name}\s+active\s+(${INTERFACES}+,?)
        ^\s+(${INTERFACES}+,?)
    

    Something like that, which lets you repeat would be gravy

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions