Skip to main content

Regular Expressions

Several functions in ZWL accepts a regex pattern. ZWL has a few rules for a valid regex pattern:

  • The pattern must be a string with no forward slashes (/../) around.

  • Named groups are written with syntax (?<name>x).

  • Regex flags in ZWL can be given using syntax (?idmsuxU)PATTERN_STARTS_FROM_HERE. See following example:

    assertTrue(find(`That Clever animalis a FOX`, '(?i)clever[\\s\\S]*fox'))
  • Since backslashes \ are used to escape characters in a string, if a pattern contains \, escape it using another backslash like so '\\s'

  • If you're writing complex regex patterns, we suggest testing them using a tool like regexr for better clarity and debugging.

info

If you need help in writing regular expressions, mdn is a great source to start with.