A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Regular expressions in C

Using glibc's regex.h
  • Make sure the number of expected matches (nmatch) is high enough, or there will be garbage at the end of the matchptr array
  • If regexec() succeeds [returns zero], matchptr contains:
    • 0: the whole regex
    • 1: first parenthesis match
  • if regexec() fails [returns a value], don't even look in matchptr
  • Characters that must be escaped:
    • parentheses
    • plus signs
  • If you're matching the end of line, it must be inside any parenthesis!