Im trying to create a pattern and to remove everything before and including the patter if possilble.
My sample text is:
Building configuration... Current configuration : 32546 bytes ! ! Last configuration change at 22:48:59 UTC Wed Jan 6 2021 by bobb ! NVRAM config last updated at 22:35:10 UTC Mon Nov 2 2020 by johns ! version 16.10
Id like anything before version removing, I didn’t mind the first ! so I have the below which gets the NVRAM line
now what would my python/regex look like to remove that NVRAM line and everything before it?
Thanks for any help
You can use
A(?:(?!! NVRAM).*n)*! NVRAM.*n* A(?:[sS]*?n)?! NVRAM.*n*
A– start of string
(?:(?!! NVRAM).*n)*– zero or more sequences of lines that do not start with
(?:[sS]*?n)?– an optional sequence (it is necessary if the line starting with
! NVRAMis the first line) any zero or more chars, as few as possible, up to the first newline char that is followed with the subsequent subpatterns
! NVRAMand the rest of the line
n*– optional zero or more newlines.