Tinderbox v9 Icon

String.extract(regexStr[, caseInsensitiveBln])


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Last Altered: 

Operator Uses Regular Expressions: 


String.extract(regexStr)

The operator returns the first matched subexpression of a quote-enclosed regular expression regexStr in the source String. If the regular expression has no subexpressions, the entire match is returned up to the end of the current line/paragraph, i.e. the first line break character encountered.

For example, take a String which is the $Text "We are very tired, Harrison! #things #Memes #August":

$MyString = $Text.extract("[A-Z][A-Za-z+]"); 

this returns "We" as that is the first match (although there are others). This sort of use is the presumed most likely used of this operator.

If we amend the regex

$MyString = $Text.extract("#([A-Z][A-Za-z+])"); 

it now returns "Memes" (the first hash tag starts with a lowercase letter does not match).

If multiple matches are expected/wanted, see String.extractAll().

String.extract(regex[, caseInsensitiveBln])

From v9.5.0, String.extract() now accepts an optional boolean second argument caseInsensitiveBln. If that argument is true, the regex argument's regular expression search is case-insensitive. The default value is false respecting the pre-existing behaviour.