# SearchGroups(4)

[Home] [Commands] [Variables] [Macro-Dev] [Glossary]

## NAME

@s0, @s1, @s2, ... @s9 - Last search group values

## SYNOPSIS

@s0 - Last search's whole match string
@s1 - Last search's first group value
@s2 - Last search's second group value
...
@s9 - Last search's nineth group value

## DESCRIPTION

The search group variables @s n return the string matches of the last regular expression search i.e. search-forward(2) (in magic(2m) mode) or search-buffer(2).

@s0 returns the whole of the matched string, @s n, n = 1..9, returns the bracket matches corresponding to the group demarkation points indicated by `\(` and `\)` in the search regular expression.

## DIAGNOSTICS

An error is generated if an attempt is made to access these variables and the last search failed or the last search did not have the specified group.

The value returned for an unused group, e.g. @s2 for the regex string "`\(a\)\|\(b\)`" if "`a`" was matched, is an empty string ("").

## EXAMPLE

The following macro code gives a simple example of their potential use:

    forward-search "Token *{\\(Start\\|End\\)}"
    !if $status
        ml-write "[found \"%s\"]" @s0
        !if &seq @s1 "Start"
           .
           .

## NOTES

Remember that the regular expression escape character '\' has to be duplicated within a macro file as '\' is also the macro file escape sequence.

## SEE ALSO

magic(2m), search-buffer(2), search-forward(2).

(c) Copyright JASSPA 2009
Last Modified: 2009/08/29
Generated On: 2009/10/12

</HMTL>