class EReg

The EReg class represents regular expressions.

While basic usage and patterns consistently work across platforms, some more complex operations may yield different results. This is a necessary trade- off to retain a certain level of performance.

EReg instances can be created by calling the constructor, or with the special syntax ~/pattern/modifier

EReg instances maintain an internal state, which is affected by several of its methods.

A detailed explanation of the supported operations is available at http://haxe.org/doc/cross/regexp

Instance Fields

function new(r:String, opt:String): Void

Creates a new regular expression with pattern r and modifiers opt.

This is equivalent to the shorthand syntax ~/r/opt

If r or opt are null, the result is unspecified.

function match(s:String): Bool

Tells if this regular expression matches String s.

This method modifies the internal state.

If s is null, the result is unspecified.

function matchSub(s:String, pos:Int, ?len:Int = -1): Bool

Tells if this regular expression matches a substring of String s.

This function expects pos and len to describe a valid substring of s, or else the result is unspecified. To get more robust behavior, this.match(s.substr(pos,len)) can be used instead.

This method modifies the internal state.

If s is null, the result is unspecified.

function matched(n:Int): String

Returns the matched sub-group n of this EReg.

This method should only be called after this.match or this.matchSub, and then operates on the String of that operation.

The index n corresponds to the n-th set of parentheses in the pattern of this EReg. If no such sub-group exists, an exception is thrown.

If n equals 0, the whole matched substring is returned.

function matchedPos(): {pos:Int, len:Int}

Returns the position and length of the last matched substring, within the String which was last used as argument to this.match or this.matchSub.

If the most recent call to this.match or this.matchSub did not match anything, the result is unspecified.

If the global g modifier was in place for the matching, the position and length of the leftmost substring is returned.

function matchedRight(): String

Returns the part to the right of the last matched substring.

If the most recent call to this.match or this.matchSub did not match anything, the result is unspecified.

If the global g modifier was in place for the matching, only the substring to the right of the leftmost match is returned.

The result does not include the matched part.