[Type] RegExp

Part of: mobl
Inherits from: mobl::Object

RegExp instances represent regular expressions. A regular expression can be used to easily and efficiently retrieve information from textual data. More on regular expressions can be found here.

Instantiation

Regular expressions are instantiated using regexp literals. Regex literals follower the same syntax as Javascript's Regexes. Another way to instantiating a regular expression is using the RegExp.fromString function:

Example:

var r = /[a-z]+/;
var r2 = /[a-z]+/i;
var r3 = RegExp.fromString("[a-z]+");

Static methods

fromString(regexp : String) : RegExp

Parses the string and turns it into a regular expression object.

Example:

var r : RegExp = RegExp.fromString("[a-z]*");

Instance methods

compile(regexp : RegExp) : void

Changes the regular expression and recompiles it.

Example:

var r = /[a-z]*/;
r.compile(/[A-Z]*/);

exec(s : String) : [String]

Executes the regular expresion on the text in s, if it matches, it will return an array of matches, if not it will return null.

Example:

var r = /[a-z]*/;
r.exec("hello there") -> ["hello"]

test(s : String) : Bool

Tests if the regular expression matches s.

Example:

var r = /[a-z]*/;
r.test("hello") -> true

Instance properties

global : Bool

Performing a global match or not.

ignoreCase : Bool

Ignoring case while matching.

lastIndex : Num

Last index matched.

multiline : Bool

Multi-line matching (. matches new lines)

source : String

Source regular expression (as a string).

mobl/regexp.txt · Last modified: 2013/10/01 02:28 (external edit)