vim で submatch が何をするのか不明です

vim で submatch が何をするのか不明です

vim の submatch({nr}) 式が何をするのかよく分かりません。マニュアルには次のように書かれています:

submatch({nr})                      *submatch()*
    Only for an expression in a |:substitute| command.  Returns
    the {nr}'th submatch of the matched text.  When {nr} is 0
    the whole matched text is returned.
    Example:
        :s/\d\+/\=submatch(0) + 1/
    This finds the first number in the line and adds one to it.
    A line break is included as a newline character.

submatch(0) が何をするのかは理解していますが、 '{nr}' 番目のサブマッチとはどういう意味ですか?

答え1

{nr}th は {number}th を意味します。この場合、置換で式を使用しない場合は \0、\1、... \9 と同じになります。参照:

:help /\1

パターン内のサブマッチは \(...\) で囲まれます。参照:

:help /\(

関連情報