HaxeDoc2

(やまだぃちぅ) #1
1 class Main {
2 static function main() {
3 var str = "XaaaYababZbbbW";
4 var r = ̃/[ab]+/g;
5 // ["X","Y","Z","W"]
6 trace(r.split(str));
7 }
8 }

10.3.5 Map


Themapmethod of a regular expression object can be used to replace matched substrings using
a custom function:
1 class Main {
2 static function main() {
3 var r = ̃/world/;
4 var s = "Hello, world!";
5 var s2 = r.map(s, function(r){
6 return "Haxe";
7 });
8 trace(s2); // Hello, Haxe!
9 }
10 }


This function takes a regular expression object as its first argument so we may use it to get
additional information about the match being done.

10.3.6 Implementation Details


Regular Expressions are implemented:


  • in JavaScript, the runtime is providing the implementation with the object RegExp.

  • in Neko and C++, the PCRE library is used

  • in Flash, PHP, C# and Java, native implementations are used

  • in Flash 6/8, the implementation is not available


10.4 Math


Haxe includes a floating point math library for some common mathematical operations. Most
of the fuctions operate on and returnfloats. However, anIntcan be used where aFloatis
expected, and Haxe also convertsInttoFloatduring most numeric operations (seeNumeric
Operators(Section 2.1.3) for more details).
Here are some example uses of the math library. See theMath APIfor all available functions.
1 class MathExample {
2 static public function main() {
3
4 var x = 1/2;
5 var y = 20.2;
Free download pdf