I’m trying to create a regex that strips out all lines that don’t start with a certain prefix. Using this tip I came up with this:
(?:(?!\nLAST-MODIFIED:[^\n]+\n).*)
This doesn’t seem to work properly. What am I doing wrong? And yes, I’m aware of the fact that this will always strip the first line, whether it is prefixed with LAST-MODIFIED: or not. But I’m positive that the first line will never be a LAST-MODIFIED: line, so it should be safe. My suggested fix would be (?:(?!(\n|^)LAST-MODIFIED:[^\n]+\n).*) if I wanted to be perfectly safe.
Will this do what you need it to?
Explanation:
^– match the beginning of a line(?!LAST-MODIFIED)– check that it doesn’t begin with last-modified[^\n]*– if the above is true, match everything until you find a line break+– repeat