regexpSplit()
The function "regexpSplit()" provides pattern matching via regular expressions.
Synopsis
int regexpSplit(string rexexp, string line, dyn_string &result, [mapping
options];
Parameter | Description |
---|---|
rexexp |
The regular expression. For permitted characters, see http://doc.qt.io/qt-4.8/qregexp.html#capturedTexts under "Characters and Abbreviations for Sets of Characters". An example would be e.g. "[a-z|A-Z]+" . This example searches for letters a-z and A-Z and the + sign searches the letter one or more times meaning the + sign stands for at least one-time repetition. With the expression "[a-z|A-Z]+", for example, you can separate letters from numbers. |
line | The string that is checked. |
result | The result of the search. |
options |
For the mapping the following keys can be used: startPosition: Set the start position for the search: (Default: int 0) caseSensitive: Set Case Sensitive matching (Default: bool false) Set minimal matching (Default: bool false): You can limit the result by using the minimal matching. The following example shows an output with the parameter "minimal" and without "minimal". dyn_string result; DebugN(regexpSplit("<b>.*</b>", "We must be <b>bold</b>, very <b>bold</b>!", result, makeMapping("minimal", FALSE))); DebugN("Result with minimal = false:", result); Debug Output: WCCOAui1:[11] WCCOAui1:["Result with minimal = false:"][dyn_string 1 items WCCOAui1: 1: "<b>bold</b>, very <b>bold</b>" dyn_string result1; DebugN(regexpSplit("<b>.*</b>", "We must be <b>bold</b>, very <b>bold</b>!", result1, makeMapping("minimal", TRUE))); DebugN("Result with minimal = TRUE - default:", result1); Debug Output: CCOAui1:["Result with minimal = TRUE - default:"][dyn_string 1 items WCCOAui1: 1: "<b>bold</b>" |
Return value
-
The function returns >=0 (Position of the match) when a match was successfully found.
-
The function returns -1 if no match was found.
-
The function returns -2 when the regular expression contains an error. Errors can be retrieved by using the function getLastError().
-
The function returns -3 when the function contains wrong arguments.
Error
See above
Description
The function "regexpSplit()" provides pattern matching via regular expressions. The function searches for the match of the specified character(s) and separates them from the string.
Example
The first example searches for letters in the string "This?is6a55Test:=regexSplit### Function" and outputs the letters:
WCCOAui1:[dyn_string 1 items
WCCOAui1: 1: "This"
WCCOAui1:]["This"]
WCCOAui1:[dyn_string 1 items
WCCOAui1: 1: "is"
WCCOAui1:]["is"]
WCCOAui1:[dyn_string 1 items
WCCOAui1: 1: "a"
WCCOAui1:]["a"]
WCCOAui1:[dyn_string 1 items
WCCOAui1: 1: "Test"
WCCOAui1:]["Test"]
WCCOAui1:[dyn_string 1 items
WCCOAui1: 1: "regexSplit"
WCCOAui1:]["regexSplit"]
WCCOAui1:[dyn_string 1 items
WCCOAui1: 1: "Function"
WCCOAui1:]["Function"]
The second example separates the words that were separated via \, from the string (Text) "Etm Company\twww.etm.at\tAustria" and outputs them:
WCCOAui1: 1: [dyn_string 4
items
WCCOAui1: 1: "Etm Company
www.etm.at Austria"
WCCOAui1: 2: "Etm Company"
WCCOAui1: 3: "www.etm.at"
WCCOAui1: 4: "Austria"
main(mapping event)
{
dyn_string
result;
int i = 0;
string s;
while( i >= 0 )
{
i = regexpSplit("[a-z|A-Z]+", ""This?is6a55Test:=regexSplit###Function"", result, makeMapping("startPosition", i + strlen(s)));
s = dynlen(result) > 0 ? result[1] : "";
DebugN(result, s);
delay(0, 100);
}
dyn_string
result;
DebugN(regexpSplit("^([^\t]+)\t([^\t]+)\t([^\t]+)$", "Etm Company\twww.etm.at\tAustria", result));
DebugN(result);
}
Assignment
Regular expressions