Packagech.capi.utils
Classpublic class Matcher
InheritanceMatcher Inheritance Object

Represents Matcher. A Matcher provides some facilty methods to do replacement using regular expressions.

View the examples



Public Properties
 PropertyDefined By
  count : int
[read-only] Defines the number of matching String found.
Matcher
  lastIndex : uint
[read-only] Defines the last index of the replacement in the source String.
Matcher
  regexp : RegExp
[read-only] Defines the RegExp used.
Matcher
  source : String
[read-only] Defines the source String.
Matcher
Public Methods
 MethodDefined By
  
Matcher(regexp:RegExp, source:String)
Creates a new Matcher object.
Matcher
  
appendReplacement(value:String):String
Replaces the current match by the specified value.
Matcher
  
appendTail():String
Appends the end of the source String to the updated String.
Matcher
  
countAll():int
Count all the matching String in the source String.
Matcher
  
find():Boolean
Find the next occurence of the RegExp.
Matcher
  
group(id:uint = 0):String
Retrieves the specified group index specified by the parenthesis.
Matcher
  
groups():int
Retrieves the number of groups in the matching RegExp.
Matcher
  
reset():void
Reset this Matcher.
Matcher
  
toString():String
Returns the modified source String if the find() and replaceMatch() methods have been used.
Matcher
Property Detail
countproperty
count:int  [read-only]

Defines the number of matching String found. This value is updated each time the method find() is called and there is a matching String.


Implementation
    public function get count():int
lastIndexproperty 
lastIndex:uint  [read-only]

Defines the last index of the replacement in the source String.


Implementation
    public function get lastIndex():uint
regexpproperty 
regexp:RegExp  [read-only]

Defines the RegExp used.


Implementation
    public function get regexp():RegExp
sourceproperty 
source:String  [read-only]

Defines the source String.


Implementation
    public function get source():String
Constructor Detail
Matcher()Constructor
public function Matcher(regexp:RegExp, source:String)

Creates a new Matcher object.

Parameters
regexp:RegExp — The regular expression to use over the source String.
 
source:String — The source String to apply the Matcher.
Method Detail
appendReplacement()method
public function appendReplacement(value:String):String

Replaces the current match by the specified value.

Parameters

value:String — The value to set.

Returns
String — The updated String.

See also

appendTail()method 
public function appendTail():String

Appends the end of the source String to the updated String.

Returns
String — The complete updated String.

See also

countAll()method 
public function countAll():int

Count all the matching String in the source String. This method is useful if you need to know how many matching there are before calling n times the find() method.

Returns
int — The number of matching String.
find()method 
public function find():Boolean

Find the next occurence of the RegExp.

Returns
Booleantrue if a match has been found.
group()method 
public function group(id:uint = 0):String

Retrieves the specified group index specified by the parenthesis. If the index is out of bounds, then an error is thrown.

Parameters

id:uint (default = 0) — The group id. 0 means the entire matching pattern.

Returns
String — The matching String.
groups()method 
public function groups():int

Retrieves the number of groups in the matching RegExp. This value contains also the group 0 which is the whole matching String.

Returns
int — The number of groups.
reset()method 
public function reset():void

Reset this Matcher.

toString()method 
public function toString():String

Returns the modified source String if the find() and replaceMatch() methods have been used.

Returns
String
Examples
     var re:RegExp = /\${(.)}/g;
     var sr:String = "This is a ${TEST} value and ${THAT} is another one => ${YEAH}";
          var m:Matcher = new Matcher(re, sr);
     while (m.find())
     {
         trace(m.group(1));
         m.appendReplacement("REPLACED");
     }
     m.appendTail();
     trace(m.toString()); //This is a REPLACED value and REPLACED is another one => REPLACED