How to match string end for a multiline string?

Discussion in 'Perl Misc' started by Peng Yu, Jun 22, 2008.

  1. Peng Yu

    Peng Yu Guest

    Hi,

    $ matches line end. When a string has multiple lines, how to much the
    last line end?

    Thanks,
    Peng
    Peng Yu, Jun 22, 2008
    #1
    1. Advertising

  2. > The "\A" and "\Z" are just like "^" and "$",
    > except that they won't match multiple times when the "/m" modifier is
    > used, while "^" and "$" will match at every internal line boundary. To
    > match the actual end of the string and not ignore an optional trailing
    > newline, use "\z"
    Damian Lukowski, Jun 22, 2008
    #2
    1. Advertising

  3. Peng Yu <> wrote:


    > $ matches line end.



    No, it matches end of string, not end of line.

    If used with //m, _then_ it matches end of line.


    > When a string has multiple lines, how to much the
    > last line end?



    /$/


    See it for yourself:

    -------------------------------
    #!/usr/bin/perl
    use warnings;
    use strict;

    $_ = '
    foo
    bar
    baz
    ';

    s/$/END-OF-STRING/;

    print;
    -------------------------------


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
    Tad J McClellan, Jun 24, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ankit
    Replies:
    2
    Views:
    262
    ankit
    Jan 10, 2006
  2. Old Echo
    Replies:
    1
    Views:
    173
    Adam Shelly
    Sep 4, 2008
  3. Ga
    Replies:
    1
    Views:
    112
    Anno Siegel
    Dec 15, 2003
  4. Vijai Kalyan
    Replies:
    9
    Views:
    160
    Tad McClellan
    Oct 19, 2004
  5. dale zhang
    Replies:
    8
    Views:
    403
    Tintin
    Nov 30, 2004
Loading...

Share This Page