Replace Regular Expression
(2 intermediate revisions by one user not shown) | |||
Line 30: | Line 30: | ||
− | [[File: | + | [[File:rplcrgx.jpg]] |
+ | == Example 2 == | ||
− | + | The example below deals with Regex groupings. | |
− | + | In the Replace Text area, instead of inserting text to replace in the original text, the grouping specifications are inserted instead. | |
+ | |||
+ | The grouping specification are: | ||
+ | |||
+ | <pre> | ||
+ | ${LastName} ${FirstName} | ||
+ | </pre> | ||
+ | |||
+ | The grouping is specifying that the resulting text should be returned in the following format: | ||
+ | |||
+ | <pre> | ||
+ | LastName FirstName | ||
+ | </pre> | ||
+ | |||
+ | <pre> | ||
+ | set(#testingregexgroup, $replace regular expression("Anna Blark", "^(?<FirstName>\\w+)\\s(?<LastName>\\w+)$", "$\{LastName\} $\{FirstName\}"), "Global") | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | When the script is run, the following results are returned: | ||
+ | |||
+ | <pre> | ||
+ | Blark Anna | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | |||
+ | == The Do Not Parse Feature == | ||
+ | |||
+ | UBot Studio will parse some symbols as math expressions. | ||
For example, t{3} means we are looking for "ttt". {3} will be parsed as a math expression. | For example, t{3} means we are looking for "ttt". {3} will be parsed as a math expression. |
Latest revision as of 21:13, 28 December 2016
$Replace Regular Expression is a Text Function.
The function returns the original text with all instances of the pattern text replaced by the replace text. The pattern text is the regex being used to find and replace the chosen text.
Original Text: The sentence or piece of data where the item that will be replaced is located. Accepts variables and functions such as $next list item, $list item, $random list item, $previous list item, and $table cell.
Pattern Text: The regex that will be used to find the item that will be replace.
Replace Text: The item that will replace the search text. Accepts variables and functions such as $next list item, $list item, $random list item, $previous list item, and $table cell.
[edit] Example 1
The regular expression:
[1]...[3]
will be looking for all numbers that start with the numbers 1 and ends with the number 3. These two numbers must have 3 other numbers between them.
set(#numbers, "51234 21324 10263", "Global") set(#numbers2, $replace regular expression(#numbers, "[1]...[3]", "REMOVED"), "Global") ui stat monitor("Resulting numbers", #numbers2)
Running the script will remove the number 10263 and replace it with the replace text "REMOVED".
[edit] Example 2
The example below deals with Regex groupings.
In the Replace Text area, instead of inserting text to replace in the original text, the grouping specifications are inserted instead.
The grouping specification are:
${LastName} ${FirstName}
The grouping is specifying that the resulting text should be returned in the following format:
LastName FirstName
set(#testingregexgroup, $replace regular expression("Anna Blark", "^(?<FirstName>\\w+)\\s(?<LastName>\\w+)$", "$\{LastName\} $\{FirstName\}"), "Global")
When the script is run, the following results are returned:
Blark Anna
[edit] The Do Not Parse Feature
UBot Studio will parse some symbols as math expressions.
For example, t{3} means we are looking for "ttt". {3} will be parsed as a math expression.
When you type that into UBot Studio, the {} around the number 3 will be removed.
To keep UBot Studio from parsing the regex as a math expression, simply click the "" (quotes) button under Pattern Text.