Prev | Current Page 409 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

replace(???-a-b-c-??™, ???-???$1???-??™);
trace(s); // -???a???-b-???c???-
}
}
Another common situation is to switch the position of terms inside a string, as shown in the following
code. The expressions look for two words separated by a space and positioned at the end of the string.
class Main
{
public static function main()
{
var re = ~/(\w+) (\w+)$/g;
var s = re.replace(???Name: John Doe??™, ???$2, $1??™);
trace(s); // Name: Doe, John
}
}
Patterns
In this section, the fundamentals of the regular expressions patterns are described. Some advanced
features have been omitted because they are beyond the scope of the book, are not fully cross - platform
(because of differences in the native - platform implementation), or are rarely used.
Characters
Patterns are composed by sequences of characters. Each character in the pattern matches itself in the
tested string, so if the pattern is the sequence abc , the tested string is matched if it contains the very
same sequence. The string passed as an argument to the match() method is the test string.


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