Regex Tips and Tricks

The above sections on the subject of regex is just a vary tiny introduction to the subject. Whole books can (and have been) written on the subject. Luckily the 80/20 rule applies, there is an 80% chance that a usable regex can be expressed using 20% or less of the regex features. To master the PCRE2 compatible regex implementation of Rax, buying one of the many books on PCRE2 regex or looking for "regex" on the world wide web is probably the best way to go. As noted before, a regex can look like a prefect solution yet, over time, grows more and more complex. Unfortunately a regex usually is write-only, meaning that even the author has a hard time figuring out how a given regex works. In Perl the x modifier can be used to ignore (unescaped) white space and comments for enhancing readability. In Rax literal string concatenation can be used to for a similar effect:

    // Build a regex that matches a C-style comment "/* ... */".
    $: re_has_c_comment :=
      '/\*'   // Match the opening delimiter.
      '.*?'   // Match a minimal number of characters.
      '\*/';  // Match the closing delimiter.
         

A word of warning though; The Regex world is a wondrous place where it is easy to squander way too much time.