Prev | Current Page 420 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Part II: Server Side, JavaScript, and Flash; Oh My!
220
Back - references are used to make assumptions on already parsed portions of the test string. In this case,
the pattern defines that the test string must begin with a vowel, be followed by any number and type of
characters, and be concluded with the same vowel encountered at the beginning (case - insensitive
because of the i option).
class Main
{
public static function main()
{
var re = ~/^([aeiou]).*\1$/i;
trace(re.match(???area??™)); // true
trace(re.match(???are??™)); // false
}
}
Alternation has the lowest priority and, thus, can be used in groups. In the following example, a non -
capturing group has been used because there is no interest in retrieving the matched portion defined by
the alternation.
class Main
{
public static function main()
{
var re = ~/j(?:oh|ea)n/i;
trace(re.match(???John??™)); // true
trace(re.match(???Jean??™)); // true
}
}
Look - around, Conditionals, and Comments
Look - around constructs permit you to verify that the pattern is preceded or followed by an expression
without including that expression in the match.


Pages:
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432