API Docs - v5.0.5
Tested Siddhi Core version: 5.1.2
It could also support other Siddhi Core minor versions.
Regex
find (Function)
Finds the subsequence that matches the given regex pattern.
Syntax<BOOL> regex:find(<STRING> regex, <STRING> input.sequence)
<BOOL> regex:find(<STRING> regex, <STRING> input.sequence, <INT> starting.index)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
regex | A regular expression that is matched to a sequence in order to find the subsequence of the same. For example, |
STRING | No | Yes | |
input.sequence | The input sequence to be matched with the regular expression. For example, |
STRING | No | Yes | |
starting.index | The starting index of the input sequence from where the input sequence ismatched with the given regex pattern.For example, |
0 | INT | Yes | Yes |
Examples EXAMPLE 1
regex:find('\d\d(.*)WSO2', '21 products are produced by WSO2 currently')
This method attempts to find the subsequence of the input.sequence that matches the regex pattern, \d\d(.*)WSO2
. It returns true
as a subsequence exists.
EXAMPLE 2
regex:find('\d\d(.*)WSO2', '21 products are produced by WSO2.', 4)
This method attempts to find the subsequence of the input.sequence that matches the regex pattern, \d\d(.*)WSO2
starting from index 4
. It returns 'false' as subsequence does not exists.
group (Function)
Returns the subsequence captured by the given group during the regex match operation.
Syntax<STRING> regex:group(<STRING> regex, <STRING> input.sequence, <INT> group.id)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
regex | A regular expression. For example, |
STRING | No | Yes | |
input.sequence | The input sequence to be matched with the regular expression. For example, 2 |
STRING | No | Yes | |
group.id | The given group id of the regex expression. For example, |
INT | No | Yes |
Examples EXAMPLE 1
regex:group('\d\d(.*)(WSO2.*)(WSO2.*)', '21 products are produced within 10 years by WSO2 currently by WSO2 employees', 3)
Function returns 'WSO2 employees', the subsequence captured by the groupID 3 according to the regex pattern, \d\d(.*)(WSO2.*)(WSO2.*)
.
lookingAt (Function)
Matches the input.sequence from the beginning against the regex pattern, and unlike regex:matches() it does not require that the entire input.sequence be matched.
<BOOL> regex:lookingAt(<STRING> regex, <STRING> input.sequence)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
regex | A regular expression. For example, |
STRING | No | Yes | |
input.sequence | The input sequence to be matched with the regular expression. For example, |
STRING | No | Yes |
Examples EXAMPLE 1
regex:lookingAt('\d\d(.*)(WSO2.*)', '21 products are produced by WSO2 currently in Sri Lanka')
Function matches the input.sequence against the regex pattern, \d\d(.*)(WSO2.*)
from the beginning, and as it matches it returns true
.
EXAMPLE 2
regex:lookingAt('WSO2(.*)middleware(.*)', 'sample test string and WSO2 is situated in trace and it's a middleware company')
Function matches the input.sequence against the regex pattern, WSO2(.*)middleware(.*)
from the beginning, and as it does not match it returns false
.
matches (Function)
Matches the entire input.sequence against the regex pattern.
Syntax<BOOL> regex:matches(<STRING> regex, <STRING> input.sequence)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
regex | A regular expression. For example, |
STRING | No | Yes | |
input.sequence | The input sequence to be matched with the regular expression. For example, |
STRING | No | Yes |
Examples EXAMPLE 1
regex:matches('WSO2(.*)middleware(.*)', 'WSO2 is situated in trace and its a middleware company')
Function matches the entire input.sequence against WSO2(.*)middleware(.*)
regex pattern, and as it matches it returns true
.
EXAMPLE 2
regex:matches('WSO2(.*)middleware', 'WSO2 is situated in trace and its a middleware company')
Function matches the entire input.sequence against WSO2(.*)middleware
regex pattern. As it does not match it returns false
.