Tinderbox v10 Icon

String.extract(regexStr[, caseInsensitiveBln])


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator in Current Baseline: 

Operator Last Altered: 

Operator Uses Regular Expressions: 

 Function  [other Function type actions]

 Item  [operators of similar scope]

 Data manipulation  [other Data manipulation operators]

 v9.1.0

 Baseline

 As at baseline

 [More on regular expressions in Tinderbox]


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])

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.