HaxeDoc2

(やまだぃちぅ) #1

5 var result = trySomething();
6 switch (result){
7 case None:
8 trace("Got None");
9 case Some(s):
10 trace("Got a value: " +s);
11 }
12 }
13
14 static function
15 trySomething():Option{
16 if (Math.random() > 0.5) {
17 return None;
18 } else {
19 return Some("Success");
20 }
21 }
22 }


10.3 Regular Expressions


Haxe has built-in support forregular expressions^1. They can be used to verify the format of a
string, transform a string or extract some regular data from a given text.
Haxe has special syntax for creating regular expressions. We can create a regular expression
object by typing it between the ̃/combination and a single/character:
1 var r = ̃/haxe/i;
Alternatively, we can create regular expression with regular syntax:
1 var r = new EReg("haxe", "i");
First argument is a string with regular expression pattern, second one is a string withflags
(see below).
We can use standard regular expression patterns such as:


  • .any character

  • *repeat zero-or-more

  • +repeat one-or-more

  • ?optional zero-or-one

  • [A-Z0-9]character ranges

  • [ˆ\r\n\t]character not-in-range

  • (...)parenthesis to match groups of characters

  • ˆbeginning of the string (beginning of a line in multiline matching mode)

  • $end of the string (end of a line in multiline matching mode)


(^1) http://en.wikipedia.org/wiki/Regularexpression

Free download pdf