Haxe has built-in support for regular expressions. They can be used to verify the format of a string, transform a string or extract some regular data from a given text.
Haxe has special syntax for creating regular expressions. We can create a regular expression object by typing it between the
~/ combination and a single
var r = ~/haxe/i;
Alternatively, we can create regular expression with regular syntax:
var r = new EReg("haxe", "i");
The first argument is a string with a regular expression pattern, the second one is a string with flags (see below).
We can use standard regular expression patterns such as:
(...)parenthesis to match groups of characters
^beginning of the string (beginning of a line in multiline matching mode)
$end of the string (end of a line in multiline matching mode)
For example, the following regular expression matches valid email addresses:
Please notice that the
i at the end of the regular expression is a flag that enables case-insensitive matching.
The possible flags are the following:
icase insensitive matching
gglobal replace or split, see below
$represent the beginning and end of a line
uuse UTF-8 matching (Neko and C++ targets only)