Add Escape Characters to Regular Expression
Verb: escapeTextForRegex
Adds escape characters to a regular expression, causing all of its characters to be interpreted literally, not as how regular expressions interpret.
Syntax
escapeTextForRegex --text(String) (String)=value
Inputs
Script | Designer | Required | AcceptedTypes | Description |
---|---|---|---|---|
--text | Regular Expression | Required | Text | Regular expression that should have escape characters added to. |
Outputs
Script | Designer | AcceptedTypes | Description |
---|---|---|---|
value | Generated Escape Text | Text | Text generated based on Regular Expression, with escape characters. |
Example
Counts the occurences in the given text of the regular expression "." . The expression dot (.) matches any character, so it returns the number of characters in the text. After adding the escape characters and redoing the count, the return is only the number of points that exist in the text.
defVar --name regularExpression --type String --value "."
defVar --name occurrencesNumber --type Numeric
defVar --name newRegularExpression --type String
defVar --name parsedText --type String --value "First row.\r\nSecond row.\r\nThird row."
countTextOccurrences --text "${parsedText}" --useRegex --regexPattern "${regularExpression}" --regexOptions "Multiline" --startindex 1 --comment "The regular expression dot (.) Matches any character" occurrencesNumber=value
logMessage --message "\r\nNumber of characters in the text: ${occurrencesNumber}" --type "Info"
escapeTextForRegex --text "${regularExpression}" --comment "When applying the command, it brings only the period (.) Character" newRegularExpression=value
countTextOccurrences --text "${parsedText}" --useRegex --regexPattern "${newRegularExpression}" --regexOptions "Multiline" --startindex 1 occurrencesNumber=value
logMessage --message "\r\nNumber of times that the period (.) Character exists: ${occurrencesNumber}" --type "Info"