While browsing I've bumped into a mindblowingly useful tool when it comes to regular expressions: Lookaround Zero-Length Assertions - https://www.regular-expressions.info/lookaround.html .

It's that thing, that set of characters, which makes your search capable of matching, for example, (beginning of a line)#, but only, if the # is preceded by | and then NEWLINE - like in orgmode spreadsheets the first of multiple formulas. So, the context behind or before is considered for matching without this context to be added into the result string as additional characters.

What made me understand this in the first place was this section:

Lookbehind has the same effect, but works backwards. It tells the regex engine to temporarily step backwards in the string, to check if the text inside the lookbehind can be matched there. (?<!a)b matches a “b” that is not preceded by an “a”,

Some research revealed that there seemed to be some effort going on to add this feature to emacs: https://emacs.stackexchange.com/a/32782

The question now is: 2023/2024 - can any of the emacs versions newer than 24.1 do it? Because this is really a great feature, irreplaceable valuable.

  • 1
    I have thoroughly read the section on regexp in the Emacs 28.2 elisp manual. I remember there wasn't such a feature, and I was planning to post a question about it but then forgot.
    – shynur
    Commented Dec 26, 2023 at 3:37
  • 2
    The normal way to approach these use-cases in Emacs is with elisp code (admittedly less of a solution for those who haven't started learning elisp, but nevertheless it provides a solution). So if you want to exclude certain cases from your main pattern, you would search for the main pattern and then as a secondary test check whether the match (or some subgroup thereof) matched your exclusion pattern, and act appropriately in either case. Pretty trivial to the elisp programmer, but not something which is provided as part of the regexp syntax.
    – phils
    Commented Dec 26, 2023 at 4:57
  • @phils Some options only accept regular expression strings, in which case one must resort to the feature described in the question. Alternatively, if the package author is meticulous and thoughtful, they may extract only a certain matched group, rather than the entire matched text.
    – shynur
    Commented Dec 26, 2023 at 14:19
  • Please don't put comments in a question or answer, referring to the comments they're commenting on. Put whatever content you like in the question, to clarify things, but don't refer to comments. Comments aren't searchable, and they can be deleted at any time. Q & A need to stand on their own. Thx.
    – Drew
    Commented Dec 26, 2023 at 17:51

1 Answer 1


Nope. The features supported by Emacs Regexeps are described in the manual, chapter 35.3 Regular Expressions in the Emacs Lisp Reference manual.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.