Prev | Current Page 421 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

That means that it is possible to check that the pattern
is followed by a certain condition without including that condition in the result. In practice the look -
around expressions do not consume characters (see Table 8 - 11 ).
The following pattern looks for any occurrence of the word John that is followed by a space and Doe but
only Joe is considered a match. If the pattern continued after the look - ahead expression, it would
resume exactly at the whitespace character that follows John .
class Main
{
public static function main()
{
var re = ~/John(?= Doe)/;
trace(re.match(???My name is John Doe??™)); // true
trace(re.matched(0)); // ???John??? and not ???John Doe???
trace(re.match(???My name is John Roe??™)); // false
}
}
Chapter 8: Cross Platform Tools
221
You can find examples for other look - around expressions in the following code. The last two matches do
not work in JavaScript because look - behind is not supported on this platform.
class Main
{
public static function main()
{
trace(~/John(?! Doe)/.


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