How can I specify a regex pattern which matches any line without
"lecture"
anywhere in it?".pdf"
at the end?
How can I specify a regex pattern which matches any line without
"lecture"
anywhere in it?
".pdf"
at the end?
For your actual problem, per the comments, M-x keep-lines
is what you're looking for, and in your case you would keep lines matching the regexp lecture\|\.pdf$
As Drew comments, you can't do what you've actually asked for with a regular expression in Emacs, as PCRE-style arbitrary zero-width look-ahead assertions are not available.
If the pattern is anchored to the beginning of the string, then it becomes practical (but still not easy) to match "strings which do not start with X". The following is a regexp which matches lines which do not start with lecture
(and are not, in their entirety, a prefix of that word):
^\([^l]\|l[^e]\|le[^c]\|lec[^t]\|lect[^u]\|lectu[^r]\|lectur[^e]\).*
You get the idea.
In rare cases that's useful, but more often you would do what Drew outlined:
Typically, if you need the opposite of what a regexp matches you find what it matches and subtract that from the original search space to get the complement.
You might also find this trick interesting:
M-x query-replace-regexp
and replace .*
with:
\,(if (string-match-p "lecture\\|\\.pdf$" \&) \& "")
Note that this is matching and replacing all lines -- but the ones which match the embedded regexp are 'replaced' with identical text, and the ones which don't are replaced with an empty string.
Adding a newline C-qC-j to the end of that .*
search pattern would produce the same textual result as keep-lines
with lecture\|\.pdf$