Regulare Expressions
Regular expressions provide tools for developing complex pattern matching and textual search-and-replace algorithms. By creating patterns to match specific strings, a developer has total control over searching, extracting, or replacing data. In short, to master regular expressions is to master your data.
destroy=re
declare=re=ue_regexp
re=init=\stest\b=true,true
re=replace=atest test testb atestb "test"= wert
message=<value>
Result from <value> : atest wert testb atestb "test"
command |
Description |
---|---|
group=<matchindex>=<groupindex>
long <matchindex> long <groupindex> |
Return String for matched Groupcount
Returns String in <ls_group> / NULL |
groupcount=<matchindex>
long <matchindex> |
Return Groupindex for matched Index of found Patten Returns groupindex in <value> / -1 |
init=<seachstring>=<global>=<IgnoreCase>
|
Initialize the object. Parameter: Pattern string define the regular expression IgnoreCase boolean (1 = true / 0 = false) default = false global boolean (1 = true / 0 = false) default = false If regular expression should test against all possible matches |
match=<matchindex> |
Returns the matched string from the matchindex Returns string into <value> |
matchcount |
Returns the number of matches into <value> |
matchlenght=<matchindex> |
Returns the total length of the matched string into <value> |
matchpos=<matchindex> |
Returns the position within the original string where the match occurred into <value> |
replace=<searchstring>=<replacestring> |
Returns the replaced string or the original string if nothing is found into <value> Parameter: searchstring ist original string repalcestring is the string you want to replace. |
search=<searchstring> |
Returns a matchindex into <value> |
test=<searchstring> |
Test the Pattern against the string and returns 1 if found otherwise 0 |
Microsoft Beefs Up VBScript with Regular Expressions
http://msdn.microsoft.com/en-us/library/ms974570.aspx
----------------[ Position matching ]----------------------------------------------
^ Only match the beginning of a string.
$ Only match the ending of a string.
\b Matches any word boundary
\B Matches any non-word boundary
----------------[ Litterals ]----------------------------------------------
Alphanumeric Matches alphabetical and numerical characters literally.
\n Matches a new line
\f Matches a form feed
\r Matches carriage return
\t Matches horizontal tab
\v Matches vertical tab
\? Matches ?
\* Matches *
\+ Matches +
\. Matches .
\| Matches |
\{ Matches {
\} Matches }
\\ Matches \
\[ Matches [
\] Matches ]
\( Matches (
\) Matches )
\xxx Matches the ASCII character expressed by the octal number xxx. ( "\50" matches "(" or chr (40). )
\xdd Matches the ASCII character expressed by the hex number dd. ( "\x28" matches "(" or chr (40). )
\uxxxx Matches the ASCII character expressed by the UNICODE xxxx. ( "\u00A3" matches "£". )
----------------[ Character Classes ]----------------------------------------------
[xyz] Match any one character enclosed in the character set. ( "[a-e]" matches "b" in "basketball". )
[^xyz] Match any one character not enclosed in the character set. ( "[^a-e]" matches "s" in "basketball". )
. Match any character except \n.
\w Match any word character. Equivalent to [a-zA-Z_0-9].
\W Match any non-word character. Equivalent to [^a-zA-Z_0-9].
\d Match any digit. Equivalent to [0-9].
\D Match any non-digit. Equivalent to [^0-9].
\s Match any space character. Equivalent to [ \t\r\n\v\f].
\S Match any non-space character. Equivalent to [^ \t\r\n\v\f].
----------------[ Repetition ]----------------------------------------------
{x} Match exactly x occurrences of a regular expression. ( "\d{5}" matches 5 digits. )
{x,} Match x or more occurrences of a regular expression. ( "\s{2,}" matches at least 2 space characters. )
{x,y} Matches x to y number of occurrences of a regular expression. ( "\d{2,3}" matches at least 2 but no more than 3 digits. )
? Match zero or one occurrences. Equivalent to {0,1}. ( "a\s?b" matches "ab" or "a b". )
* Match zero or more occurrences. Equivalent to {0,}.
+ Match one or more occurrences. Equivalent to {1,}.
----------------[ Alternation & Grouping ]----------------------------------------------
() Grouping a clause to create a clause. May be nested. "(ab)?(c)" matches "abc" or "c".
Alternation combines clauses into one regular expression and then matches any of the individual clauses. ( "(ab)|(cd)|(ef)" matches "ab" or "cd" or "ef". )
----------------[ BackReferences ]----------------------------------------------
()\n Matches a clause as numbered by the left parenthesis
"(\w+)\s+\1" matches any word that occurs twice in a row, such as "hubba hubba."
--------------------------------------------------------------
addition of the the group() and groupcount() methods to get the content of matched groups
===============================
string Pattern - Searchstring
bool IgnoreCase
bool Global – Page or Line
intialize(Pattern,IgnoreCase,Global) Set Operationmode an Pattern
intialize() Re intialize from Instance Variables
--------------------------------------------------------------
bool=Test( teststring ) True / False
string=Replace( seachstring, replacestring ) Returns Resultstring
Search(seachstring) Returns the number of matches / notfound -1
MatchCollection Object
===============================
long Count
Matchcount() Returns the number of matches
--------------------------------------------------------------
Match Object
===============================
long FirstIndex
long Length
string Value
string=match(Index) Returns the string that matches
long=matchlenght(Index) Returns lenght auf the matchstring
long=matchposition(Index) Returns position of the matchstring in the seachstring
--------------------------------------------------------------
Group
===============================
long=groupcount(MatchIndex) Returns mumber of groupmatches from the index / nothing found -1
string=group(MatchIndex,Groupindex) Returns Groupstring / nothing found null