Add count to regex match, so only first occurance is matched #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR to limit the header pattern match in the XE driver to the first occurrence.
Justification:
The "S" flag in the pattern match is very slow in python regex.
OUTPUT_HEADER_PATTERN = re.compile( pattern=r".*(?=(version \d+\.\d+))", flags=re.I | re.S, )
Default behavior in Scrapli_Cfg is to run this regex pattern on the entire config file to remove any text before the actual configuration.
This pattern will only be seen once in a valid configuration file. This PR limits the match to the first occurrence, so that we don't have to regex the entire file, significantly speeding up the processing of the new config.
On my test config (>18000 lines), this speed up the processing from 2 hours, to less than a second, and still performed the required task of removing anything above the start of the configuration
From what i can see, the Async driver references this one, so we don't need to adjust anything there, and the other Cisco drivers don't use the "S" flag so won't have the same processing issue.
Let me know if there is anything i have missed or if you have any other contributing requirements.
Thanks