SUBSTRINGSTART Function
Returns the start location 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 sub-pattern whose starting location you want to be returned.
| Requirement | n must not be NULL or blank. |
|---|
Details
The SUBSTRINGSTART function takes the input integer n that you supply and returns a starting location for the sub-pattern represented by that input integer. NULL is returned if there is no substring currently under consideration and therefore no location to return.
Use SUBSTRINGCOUNT( ) to determine the number of sub-patterns under consideration. Use SUBSTRINGLENGTH( ) with this function to pull out the matched sub-patterns and use them in evaluation logic of your expression code.
Most simple regular expressions will not have sub-patterns and this function will behave similarly to MATCHSTART(). However, if your regular expression does use sub-patterns, then this function can be used to find the starting point 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