google / textfsm

Python module for parsing semi-structured text into python tables.
Apache License 2.0
1.12k stars 175 forks source link

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

Open harro opened 5 years ago

harro commented 5 years ago

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

itdependsnetworks commented 5 years ago

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.

gachteme commented 5 years ago

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.

boniek83 commented 4 years ago

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

DanSheps commented 3 years ago

Has there been any movement on this at all?

giovanni-bellini-argo commented 5 months ago

👀 still in future plans?

harro commented 1 month ago

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.

giovanni-bellini-argo commented 1 month ago

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?

harro commented 12 hours ago

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.