Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to match string end for a multiline string?

Reply
Thread Tools

How to match string end for a multiline string?

 
 
Peng Yu
Guest
Posts: n/a
 
      06-22-2008
Hi,

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

Thanks,
Peng
 
Reply With Quote
 
 
 
 
Damian Lukowski
Guest
Posts: n/a
 
      06-22-2008
> 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"

 
Reply With Quote
 
 
 
 
Tad J McClellan
Guest
Posts: n/a
 
      06-24-2008
Peng Yu <(E-Mail Removed)> 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/"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
String#match vs. Regexp#match - confused Old Echo Ruby 1 09-04-2008 06:11 PM
how to define a variable to hold a multiline text input in perl from html multiline textbox dale zhang Perl Misc 8 11-30-2004 06:53 AM
m/(\/\*[.|\n]*\*\/)/ to try and match C-Style multiline comments. No matches found. Vijai Kalyan Perl Misc 9 10-19-2004 09:49 PM
[NEWBIE] Multiline match on two files ignoring newlines, tabs & blank chars Ga Perl Misc 1 12-15-2003 11:31 AM



Advertisments