Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Clarified the bullet list outlining differences between slashy and string based regexes

...

Code Block
// 3. here document string converted to a regex
regex = '''(?ix)(\\d+)\\s+\\d+%\\s+(/nfs/data.*)'''
pattern = ~regex

Essentially, when converting a slashy regex to a string based pattern:

  • Forward slashes don't need to be escaped by back slashes so "\/" becomes "/"
  • Double the remaining back slashes. Back slashes need to be escaped by back slashes when quoting strings (either normal or here documents)
  • If you want to match whitespace, then you must use
    No Format
    \\s
  • You can match "#" with
    No Format
    \\#
    so that it's not interpreted as the beginning of a comment

...