A regular expression (regex or regexp for short) is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids. You are probably familiar with wildcard notations such as .txt to find all text files in a file manager. The regex equivalent is ^..txt$.

  • All lines that start with a Markdown heading
    • ^(#\s.*)\n
  • Match previours expression two or more times
    • {2,}
    • e.g. #{2,}\s.* matches ## Test but not # Test
  • Find all instances of ISO datetimes that don’t have brackets around them already and which aren’t in frontmatter
    • ((?<!date: |lastmod: |\[\[)\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(?!\]\]))
  • Match anything up until a sequence of characters
    • .+?(?=abc)
    • “When using .+?, instead of matching all at once and going back for other conditions (if any), the engine will match the next characters by step until the subsequent part of the regex is matched (again if any). This is the un-greedy, meaning match the fewest possible to satisfy.”

Siehe auch linux-cli-sed und linux-cli-awk.