As action code syntax eclipses older syntaxes there is some scope for confusion where regular expressions (regex) are used. With 'dot' operators, e.g. String.contains(regex), one of the options for the 'regex' input argument is a regular expression which needs to be quoted, i.e. enclosed in double quotes. This conforms to a general rule of thumb that anything that is a string (literal, template name, regex, etc.) should be quoted. This helps Tinderbox to detect where the parameter is actually an expression.
The exception to this is the long standing, but now deprecated, AttributeName(regex) operator originally introduced as part of the query language; with this do not quote your regular expression. This operator should new be considered deprecated in favour of the $Attribute.contains(regex) operator. Thus:
$MyString(\W+) (now deprecated)