Informally the regular expression
is also known with its abbreviation regex that will be used for brevity in the rest of the chapter.
The EReg Class
The EReg class in the default package is there where the regex functionalities are implemented. The class
methods are described in Table 8 - 4 , and you will find many examples of usages in the rest of the section
and in the section dedicated to the regex patterns.
Because regular expressions are so important in everyday programming, haXe has also a specific syntax
to declare them that elegantly replaces the EReg constructor.
The regex special syntax is easier to understand with an example; two following lines are equivalent.
var re = new EReg(???pattern???, ???gim???);
var re = ~/pattern/gim;
Note that you can use the canonical dot - syntax also with the regex special syntax.
var name = ???John Doe???;
// check that the var contains the word ???John??? (case-insensitive)
if(~/john/i.match(name))
{
// ... do something here
}
(continued)
Chapter 8: Cross Platform Tools
211
Options
Some optional modifiers, described in Table 8 - 5 , can affect the behavior of the pattern.
Pages:
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415