2

regcmp()どのように動作するかを理解しようとしてregex()います。私のコードは

int main()
{ 
    char *newcursor, *name; char *string; char ret0[9];

    name = regcmp("([A-Za-z][A-za-z0-9]{0,4})$0", (char *)0);
    printf("name %s\n",&(*name));
    newcursor = regex(name, "filter:attrsonly:attrs", ret0);
    printf("newcursor %s  and ret0 %s\n",newcursor,ret0);
    return 0;
}

ここで 12 行$0目では、パターンの最後で何を([A-Za-z][A-za-z0-9]{0,4})$0 意味しますか?

UNIX から LINUX にコードを移植するために、LINUX のregex()andregcmp()regexec()andに置き換えます。LINUX にはありません。regcomp()regcmp()regex()

パターンからのみ削除$0すると、 の実行時に LINUX で期待される結果が得られregcomp()ます。とは$0どういう意味ですか?

4

1 に答える 1

1

引用させてくださいman 7 regex

     '$' (matching the null string at the end of a line),

UNIX プログラムが基本的な正規表現を使用していた可能性があります。

    Obsolete ("basic") regular expressions differ in several respects.
     [ ... ]
    '$' is  an  ordinary  character except  at the end of the RE or(!)
    the end of a parenthesized subexpression
     [ ... ]

編集:わかりました、私はunixregcmpも調べるべきでした-あなたはすでにそれを行っていると思いました:

   ( ... )$n         The value of the enclosed regular expression is to be
                     returned. The value will be  stored  in  the  (n+1)th
                     argument following the subject argument. At most, ten
                     enclosed regular expressions are allowed. The regex()
                     function makes its assignments unconditionally.

したがって、この場合、$0一致の結果がどこに行くべきかを指定するだけなので、そのままにしておくことができます。

于 2012-05-09T08:35:06.963 に答える