Prev | Current Page 417 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


{n,m} Where n and m are positive integer valued and m is greater than or equal to n. The
expression must exist between n and m times.
{n,} Where n is a positive integer value. The expression must exist at least n times.
In the following example, the pattern matches any occurrence of the character j followed by any kind
of character and by the n character:
class Main
{
public static function main()
{
var re = ~/(j.+n)/i;
trace(re.match(???John??™)); // true
trace(re.matched(1)); // John
trace(re.match(???John and Jane??™)); // true
trace(re.matched(1)); // John and Jan
}
}
Chapter 8: Cross Platform Tools
219
The first match is easy to understand but the second requires an explanation; someone may have
expected that the matched value of the second match() could be John and not John and Jan . To
understand what has happened you have to know that the regular expression engines are said to be
eager. Because the . character matches any character, the first occurrence of the n in John is consumed
by the dot while the one in Jane must necessarily be consumed by the n pattern for a match to occur.


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