[]
This dynamic array function helps to extract the matching substring according to a regular expression. Dynamic arrays are the resizable arrays that calculate automatically and return values into multiple cells based on a formula entered in a single cell. Before using this function, you need to turn on the allowDynamicArray option.
SJS.REGEXEXTRACT(text, regular_expression, [modifiers])
This function has the following arguments:
Argument | Description |
---|---|
text | Refers to the text you are trying to search. The function can input a string, a cell reference, or a cell range reference. |
regular_expression | Refers to the first part of text that matches the regular expression that is returned. |
modifiers | [Optional] Input to define the pattern.
|
You can use this function with text (not numbers) as input and return text as output.
If you want a number as output. Use the VALUE function in conjunction with this function.
If you want to use a number as input, convert them to text using the TEXT function.
spread.options.allowDynamicArray = true;
set allowDynamicArray to true for all the examples
SJS.REGEXEXTRACT("I think SpreadJS is Good", ".*(good).*", "i")
gives the result Good
SJS.REGEXEXTRACT("There are 195 countries in the world", "\d+")
gives the result 195
SJS.REGEXEXTRACT("You can also extract multiple values from text.", "You can also (\w+) multiple (\w+) from text.")
gives the result ["extract", "values"]
Errors
returns a #VALUE! error if the value type of text or regular_expression is not text.
returns a #N/A error if the length of the parameters < 2.
returns a #NAME error if any parameter is not valid.
returns a #N/A error if regular_expression does not match the text.
returns a #SPILL error if array result is not expanded.