Skip to main content

substr (Function)

Returns a substring of the input string by considering a subset or all of the following factors: starting index, length, regular expression, and regex group number.

Syntax

<STRING> str:substr(<STRING> input.string, <INT> begin.index)
<STRING> str:substr(<STRING> input.string, <INT> begin.index, <INT> length)
<STRING> str:substr(<STRING> input.string, <STRING> regex)
<STRING> str:substr(<STRING> input.string, <STRING> regex, <INT> group.number)

Query Parameters

NameDescriptionDefault ValuePossible Data TypesOptionalDynamic
input.stringThe input string to be processed.STRINGNoYes
begin.indexStarting index to consider for the substring.-INTYesYes
lengthThe length of the substring.`input.string`.length - `begin.index`INTYesYes
regexThe regular expression that should be matched with the input string.-STRINGYesYes
group.numberThe regex group number0INTYesYes

Example 1

substr("AbCDefghiJ KLMN", 4)

This outputs the substring based on the given begin.index. In this scenario, the output is "efghiJ KLMN".

Example 2

substr("AbCDefghiJ KLMN",  2, 4)

This outputs the substring based on the given begin.index and length. In this scenario, the output is "CDef".

Example 3

    substr("gdnD efghiJ KLMN", '^gdn(.*)')

This outputs the substring by applying the regex. In this scenario, the output is "gdnD efghiJ KLMN".

Example 4

substr("gdn cep gdn XX E hi hA gdn heAllo",  'gdn(.*)A(.*)',  2)

This outputs the substring by applying the regex and considering the group.number. In this scenario, the output is " ello".