Regex negative lookahead - not preceded by

المعرفة:: Regex
الحالة:: ملاحظة_مؤرشفة
المراجع:: https://stackoverflow.com/a/7317116


A zero-width negative lookahead:

  • Line starts with title then whatever not followed by space
^title:(?! )(.*))  

The (?!...) part means “only match if the text following (hence: lookahead) this doesn’t (hence: negative) match this. But it doesn’t actually consume the characters it matches (hence: zero-width).

There are actually 4 combinations of lookarounds with 2 axes:

  • lookbehind / lookahead : specifies if the characters before or after the point are considered
  • positive / negative : specifies if the characters must match or must not match.

Last update : August 14, 2023
Created : August 23, 2022

Comments

Comments