Prev | Current Page 418 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


How do you prevent this behavior? By changing the way the engine works and making it lazy . Any
quantifier can be suffixed with an optional question mark ? symbol. If present, the expression is processed
in lazy mode. That means that after the j has been encountered; the following dot expression is
applied as little as possible. In this case the engine tries to apply it just once and matches the o of John
and tries to apply the next expression n to the following character h . Because there is no correspondence,
the engine rolls back and tries again to apply the dot expression on the h character obtaining a success.
This time the next expression n matches correctly and the engine ends its process successfully.
class Main
{
public static function main()
{
var re = ~/(j.+?n)/i;
trace(re.match(???John and Jane??™)); // true
trace(re.matched(1)); // John
}
}
Grouping, Alternation, and Back - references
A pattern can include groups. Any matched group can be extracted using the function matchedGroup()
with the numeric id of the group as argument (Table 8 - 10 ).


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