REGEX_COUNT
Use the REGEX_COUNT script function to count occurrences of a pattern in a string or process handle. You can use this scripting element with regular expressions, process handles, and also select specific columns and work only within them. If you are working with process handles, the function will count occurrences across all lines. To find multiple occurrences within a single line, make sure to activate the 'g' flag.
Note: The terms Data Sequences and Text Containers are used interchangeably.
Parameters
When used with a string:
REGEX_COUNT (String, Regex [, Column[, Flags]])
When used with a process handle:
REGEX_COUNT (Handle, Regex [, Column[, Flags]])
Parameters
-
String or Handle
Unicode character string or handle to search.
Format: script literal or script variable
-
Regex
Regular expression to be used.
The regular expression use the Boost C++ Libraries syntax. For more information, see the official Boost C++ Libraries documentation.
-
Column
(Optional) The index indicates which column to search, beginning with 1, or the entire line if the index is 0.
If the text container (data sequence) loaded had columns defined, you can select a specific column and use this script element to work within the relevant column. To do so, make sure you know which column delimiter was used at the time of loading the text container (data sequence). Otherwise, you can define the delimiter using the ādā flag.
Format: script literal, script variable or number without quotation marks, Column number or 0 for plain line.
Default value: 0
-
Flags
(Optional) Use flags to modify the operation. The flags available are:
-
i: Case-insensitive
By default, the search is case sensitive.
-
g: Globally (applies to all occurrences in a line instead of only one or only the first)
When provided, the function finds all matches in a line; if it is not provided, the function only finds the first match in a line
-
n: Not match null (for example, with "\d*")
The "*" qualifier searches for zero or more occurrences of a pattern and tries to find as many occurrences as possible. This might return zero occurrences. Setting this flag avoids that behavior.
-
d: Delimiter that separates columns
Allows you to define a specific delimiter, which can be any text of at least one character, to virtually break up text into columns. The delimiter is enclosed by the character immediately following the "d". This overwrites any default delimiter that the text container might have. For example:
d' ' for a single blank space
d'$$' for a sequence of two dollar signs
d+,+ for a comma
d!foo! for the word "foo"
Flags can be combined and provided in any order. For example, if you combine flag i with flag n, you can do so using "in" or "ni", or the script variable &FLAG#. An exception is the flag "d", which can be used to specify a multi character sequence as a delimiter used to separate columns in a text.
-
Example 1
Counting files by type:
!* Regex
:SET ®EX_TXT# = "\.txt$"
:SET ®EX_EXE# = "\.exe$"
:SET ®EX_ZIP# = "\.zip$"
:SET ®EX_INI# = "\.ini$"
!* Count files in directory structure by type
:SET &HND# = PREP_PROCESS_FILENAME(AR_MAIN_JWX6_VFRKARWIN01_01, "C:\Temp\*", "Y", "Y",,,,"UC_LOGIN=AR.LOGIN.OK")
:SET &CNT_TXT# = REGEX_COUNT(&HND#, ®EX_TXT#, , "i")
:SET &CNT_EXE# = REGEX_COUNT(&HND#, ®EX_EXE#, , "i")
:SET &CNT_ZIP# = REGEX_COUNT(&HND#, ®EX_ZIP#, , "i")
:SET &CNT_INI# = REGEX_COUNT(&HND#, ®EX_INI#, , "i")
!* Output
:PRINT Text files:&CNT_TXT#
:PRINT Executables: &CNT_EXE#
:PRINT ZIP files:&CNT_ZIP#
:PRINT INI files:&CNT_INI#
After running the script, the Activation report (ACT) displays the following:
2025-08-04 18:36:38 - U00020408 Text files: 0000000000000044 2025-08-04 18:36:38 - U00020408 Executables: 0000000000000001 2025-08-04 18:36:38 - U00020408 ZIP files: 0000000000000004 2025-08-04 18:36:38 - U00020408 INI files: 0000000000000006
Example 2
Checking for errors in a report in Post Processing:
!* Regex
:SET ®EX# = "permission denied|no such file or directory"
!* Check for errors in job report
:SET &HND# = PREP_PROCESS_REPORT()
:IF REGEX_COUNT(&HND#, ®EX#, , "i") <> 0
: PRINT "File errors found."
:ENDIF
After running the Job, the Post processing report (POST) displays the following:
2025-08-06 10:44:43 - U00020408 File errors found.
The Job report (REP) has further information:
Program 'UC4 Job Messenger' version '24.6.0+low.build.1754411700712' started UCMDJP: ********************************************************************* UCMDJP: ** JOB 0074026484 (ProcID:0002079637) START AT 06.08.2025/10:44:43 ** UCMDJP: ** UTC TIME 06.08.2025/08:44:43 ** UCMDJP: ********************************************************************* ls: cannot access 'does_not_exist.txt': No such file or directory ls: cannot access 'does_not_exist_also.txt': No such file or directory total 88507 [...]
See also: