RegularExpressionNamedGroup()

Syntax

Result$ = RegularExpressionNamedGroup(#RegularExpression, GroupName$)
Description
Extract the string matched by a named group within the regular expression after a call to NextRegularExpressionMatch().

Parameters

#RegularExpression The regular expression to use. ExamineRegularExpression() and NextRegularExpressionMatch() must have been called on this regular expression.
GroupName$ The name of the group to extract. The group name is case sensitive.

Return value

Returns the string matched by the regular expression group.

Remarks

Groups in a regular expression are defined by surrounding a sub-expression with braces "(" and ")". Groups can either accessed by index using functions like RegularExpressionGroup() or they can be assigned a name using the "(?<name>)" syntax as shown in the example below.

Example

  ; This expression matches a color setting string (with value red, green or blue)
  ; The colors are grouped with () which has the name "col" assigned to it.
  ; This color name is then extracted
  ;  
  If CreateRegularExpression(0, "color=(?<col>red|green|blue)")
    If ExamineRegularExpression(0, "stype=bold, color=blue, margin=50")
      While NextRegularExpressionMatch(0)
        Debug "The color is " + RegularExpressionNamedGroup(0, "col")
      Wend
    EndIf
  Else
    Debug RegularExpressionError()
  EndIf

See Also

ExamineRegularExpression(), NextRegularExpressionMatch(), RegularExpressionNamedGroupPosition(), RegularExpressionNamedGroupLength(), RegularExpressionGroup()

Supported OS

All

<- RegularExpressionMatchString() - RegularExpression Index - RegularExpressionNamedGroupLength() ->