User Guide

Regular expression syntax 301
Note that only the \n character signals the end of a line. The following characters do not:
Return (\r) character
Unicode line-separator (\u2028) character
Unicode paragraph-separator (\u2029) character
The s (dotall) flag
If the s (dotall or “dot all”) flag is not set, a dot (.) in a regular expression pattern does not
match a newline character (
\n). So for the following example, there is no match:
var str:String = "<p>Test\n";
str += "Multiline</p>";
var re:RegExp = /<p>.*?<\/p>/;
trace(str.match(re));
However, if the s flag is set, the dot matches the newline character:
var str:String = "<p>Test\n";
str += "Multiline</p>";
var re:RegExp = /<p>.*?<\/p>/s;
trace(str.match(re));
In this case, the match is the entire substring within the <p> tags, including the newline
character:
<p>Test
Multiline</p>
The x (extended) flag
Regular expressions can be difficult to read, especially when they include a lot of metasymbols
and metasequences. For example:
/<p(>|(\s*[^>]*>)).*?<\/p>/gi
When you use the x (extended) flag in a regular expression, any blank spaces that you type in
the pattern are ignored. For example, the following regular expression is identical to the
previous example:
/ <p (> | (\s* [^>]* >)) .*? <\/p> /gix
If you have the x flag set and do want to match a blank space character, precede the blank
space with a backslash. For example, the following two regular expressions are equivalent:
/foo bar/
/foo \ bar/x