Count Occurrences in Text
Verb: countTextOccurrences
Counts the number occurrences of specific text, such as terms, phrases, numbers, or expressions in a larger text.
Syntax
countTextOccurrences --text(String) [--useRegex(Boolean)] --query(String) --regexPattern(String) [--regexOptions(DisplayableRegexOptions)] --startindex(Numeric) (Numeric)=value
Inputs
Script | Designer | Required | AcceptedTypes | Description |
---|---|---|---|---|
--text | Text to Parse | Required | Text | Text in which ocurrences are counted. |
--useRegex | Use regular expression | Optional | Boolean | Enables search by regular expression. |
--query | Text to Find | Only whenUse regular expression is False | Text | Text occurrence counted. |
--regexPattern | Regular expression | Only whenUse regular expression is True | Text | Regular expression used for counting occurrences in Text to Parse . |
--regexOptions | Options | Optional | DisplayableRegexOptions | Filtering options that assist in regular expression search:
|
--ignorecase | Ignore case(Obsolete) | Optional | Boolean | When enabled, specifies case-insensitive matching.
This parameter is obsolete. To select regular expression options, use the Options instead. |
--dotmatchesnewline | Dot matches new line(Obsolete) | Optional | Boolean | When enabled, the dot (.) character matches every character, instead of every character except "\n".
This parameter is obsolete. To select regular expression options, use the Options instead. |
--freespacing | Ignore white space(Obsolete) | Optional | Boolean | When enabled, eliminates blank spaces and breaks without adding a escape character.
This parameter is obsolete. To select regular expression options, use the Options instead. |
--explicitcapture | Explicit capture(Obsolete) | Optional | Boolean | When enabled, specifies that the only valid captures are explicitly named or numbered groups of the form (?
This parameter is obsolete. To select regular expression options, use the Options instead. |
--multiline | Multiline(Obsolete) | Optional | Boolean | When enabled, changes the meaning of ^ and $ so they match at the beginning and end, respectively, of any line, and not just the beginning and end of the entire string.
This parameter is obsolete. To select regular expression options, use the Options instead. |
--startindex | Position | Required | Number | Text position where the search starts, with each character corresponding to a position. |
Outputs
Script | Designer | AcceptedTypes | Description |
---|---|---|---|
value | Count | Number | Number of occurrences found. |
Example
Example 1: Counts the number of occurrences of the word Brazil in Text to Parse .
defVar --name sampleText --type String --value "IBM Robotic Process Automation! AUTOMATION MARKET LEADER IN BRAZIL!"
defVar --name numberOfOccurrences --type Numeric
// Count the occurrences of the word "BRAZIL" in the sample text.
countTextOccurrences --text "${sampleText}" --query BRAZIL --startindex 1 numberOfOccurrences=value
logMessage --message "${numberOfOccurrences}" --type "Info"
// After executing the command, the variable "numberOfOccurrences" receives the value "1", because the word "BRAZIL" occurs once in the text.
Example 2: Counts the number of occurrences of the letter "A" in the text.
defVar --name sampleText --type String --value "IBM Robotic Process Automation!"
defVar --name numberOfOccurrences --type Numeric
countTextOccurrences --text "${sampleText}" --query A --startindex 2 numberOfOccurrences=value
logMessage --message "${numberOfOccurrences}" --type "Info"
// After executing the command, the variable "numberOfOccurrences" receives the value "1".
Remarks
The Count Occurrences in Text command is a case-sensitive command, so you must distinguish uppercase from lowercase letters in Text to Parse .
All character types are accepted in the Text to Find parameter.
More than one filtering option can be accepted in the Options parameter.