Prev | Current Page 406 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


class Main
{
public static function main()
{
var re = ~/b(c)d/;
re.match(???abcde??™);
trace(???string: ??? + re.matched(0)); // bcd
trace(???group: ??? + re.matched(1)); // c
trace(???left: ??? + re.matchedLeft()); // a
trace(???right: ??? + re.matchedRight()); // e
var p = re.matchedPos();
trace(???pos: ??? + p.pos + ???, len: ??? + p.len); // pos: 1, len: 3
}
}
Although you can define more than one group for pattern, it is not possible to retrieve more than one
occurrence of each group at once. To do so you have to repeat the match() method on the remaining
portion of the string using the result of matchedRight() as the test value as illustrated in the following
code. The expression looks for any word of length between four and five characters.
class Main
{
public static function main()
{
var re = ~/(\b\w{4,5}\b)/;
var s = ???The quick brown fox jumps over the lazy dog???;
var results = new List();
Table 8-5
Option Name Description
g global When used with replace() or split() the operation is repeated
for each occurrence of the pattern and will not stop on the first.


Pages:
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418