REGEX_COUNT
Use the REGEX_COUNT script function to count occurrences of a pattern in a string or process handle. You can use this script element with regular expressions and process handles, and you can also select specific columns and work only within them. With process handles, the function counts occurrences across all lines. To find multiple occurrences within a single line, activate the 'g' flag.
Note: The terms Data Sequences and Text Containers are used interchangeably.
Syntax
When used with a string:
REGEX_COUNT (String, Regex [, Column[, Flags]])
When used with a process handle:
REGEX_COUNT (Handle, Regex [, Column[, Flags]])
Parameters
| Parameter | Description | Format | Allowed Values | Default Value |
|---|---|---|---|---|
| String or Handle | Unicode character string or handle to search | Script literal or script variable | n.a. | n.a. |
| Regex | Regular expression to use. The regular expression uses the Boost C++ Libraries syntax. For more information, see the official Boost C++ Libraries documentation. | Script literal or script variable | n.a. | n.a. |
| Column
(Optional) |
The index indicates which column to search, beginning with 1, or the entire line if the index is 0. If the loaded text container (data sequence) had columns defined, you can select a specific column and work within it; to do so, you must know which column delimiter was used when the text container was loaded. Otherwise, you can define the delimiter using the 'd' flag. | Script literal, script variable, or number without quotation marks | n.a. | 0 |
| Flags
(Optional) |
(Optional) Use flags to modify the operation. The flags available are: Flags can be combined and provided in any order — for example, combine i with n as "in" or "ni", or use the script variable &FLAG#. |
Script literal or script variable |
|
n.a. |
Examples
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: