Prev | Current Page 416 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

In this case the string is a match only if it contains
alphanumeric characters (or the underscore symbol) and no other characters. The second example
fails because there is a whitespace at the end.
class Main
{
public static function main()
{
var re = ~/^\w+$/;
trace(re.match(???John??™)); // true
trace(re.match(???John ???)); // false
}
}
Quantifiers
Characters, character classes, character sets, or groups can be repeated in a pattern using the quantifiers.
This avoids error - prone repetitions, pattern bloating, and of course gives the opportunity to set optional
repetitions or limit the repetitions to a range of values. The quantifiers described in Table 8 - 9 always
follow a pattern expression that can be a single character or a more complex group.
Table 8-9
Syntax Description
? The expression is optional.
* The expression can be repeated without limits or be absent.
+ The expression must be present and can be repeated several times.
{n} Where n is a positive integer value. The expression must exist exactly n times.


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