SUBSTRINGLENGTH Function
Returns the length of the n captured sub-pattern.
| Category: | Regular Expression |
|---|---|
| Requirement: | The regular expression must contain sub-patterns that can be used to match patterns. |
| Returned data type: | Integer |
Table of Contents
Syntax
Required Argument
n
specifies a positive integer that indicates the substring whose length you want to be returned.
| Requirement | n must not be NULL or blank. |
|---|
Details
The SUBSTRINGLENGTH function returns a positive integer value that represents the number of characters found to be a sub-pattern match of the regular expression. NULL is returned if there is no substring currently under consideration and therefore no length to return. For more information about working with sub-patterns, see the Details section of SUBSTRINGCOUNT Function.
Most simple regular expressions do not have sub-patterns, and this function behaves similarly to MATCHLENGTH( ). However, if your regular expression does use sub-patterns, then this function can be used to find the length of individually captured sub-patterns found within the overall matched pattern.
Example
//Define some variables
string MyString
string MyString2
integer i
integer SSC
integer SSS
integer SSL
// Set initial values for variables
i = 0
SSS = 0
SSL = 0
SSC = 0
// Sample inpit string
MyString = "DataFlux Data Management Studio"
// Define a regular expression object
regex r
// Then compile it - notice the use of ( and )
r. compile("(DataFlux|DF) Data Management (Studio|Platform)")
// Find the first substring
if r.findfirst(MyString)
begin
// Use the "substring" functions to find the number of substrings
SSC = r.substringcount()
// Loop through substrings
for i = 1 to SSC
begin
// Then pull out substrings
SSS = r.substringstart(i)
SSL = r.substringlength(i)
MyString2 = mid(MyString,SSS,SSL)
// Place the substrings in a data row
pushrow()
end
end
// Terminate the expression node processing
seteof(true)
// Prevent the last pushrow() from showing up twice
return false