Difference between \z and \Z and \a and \A in Perl

前端 未结 2 1071
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-24 16:49

Can you please tell me the difference between \\z and \\Z as well as \\a and \\A in Perl with a simple example ?

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-24 17:26

    The following indicates the positions at which the relevant regex patterns will match ( indicates a line feed):

    \A                       \A is not affected by /m
    ^                        ^ without /m             ≡ \A
    ^/m  ^/m  ^/m            ^ with /m                ≡ \A|(?<=\n)
    |    |    |
    |    |    |
    v    v    v
    abc␊def␊ghi␊
       ^    ^    ^^
       |    |    ||___
       |    |    |    |
       $/m  $/m  $/m  $/m    $ with /m                ≡ (?=\n)|\z
                 $    $      $ without /m             ≡ (?=\n\z)|\z
                 \Z   \Z     \Z is not affected by /m ≡ (?=\n\z)|\z
                      \z     \z is not affected by /m
    

    \a is equivalent to \x07, meaning it matches character 0x07 (BEL/BELL in ASCII and UNICODE).

    This is documented in perlre.

提交回复
热议问题