| Package | ch.capi.utils |
| Class | public class Matcher |
| Inheritance | Matcher Object |
Matcher provides some facilty methods to do replacement
using regular expressions.
| Property | Defined 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 | ||
| Method | Defined 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 | ||
| count | property |
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.
public function get count():int| lastIndex | property |
lastIndex:uint [read-only]
Defines the last index of the replacement in the source String.
public function get lastIndex():uint| regexp | property |
regexp:RegExp [read-only]
Defines the RegExp used.
public function get regexp():RegExp| source | property |
source:String [read-only]
Defines the source String.
public function get source():String| Matcher | () | Constructor |
public function Matcher(regexp:RegExp, source:String)
Creates a new Matcher object.
regexp:RegExp — The regular expression to use over the source String.
| |
source:String — The source String to apply the Matcher.
|
| appendReplacement | () | method |
public function appendReplacement(value:String):StringReplaces the current match by the specified value.
Parameters
value:String — The value to set.
|
String — The updated String.
|
See also
| appendTail | () | method |
public function appendTail():String
Appends the end of the source String to the updated String.
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.
int — The number of matching String.
|
| find | () | method |
public function find():Boolean
Find the next occurence of the RegExp.
Boolean — true if a match has been found.
|
| group | () | method |
public function group(id:uint = 0):StringRetrieves 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.
|
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.
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.
String |
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