Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Regular Expression Grabbing

Reply
Thread Tools

Regular Expression Grabbing

 
 
Owen
Guest
Posts: n/a
 
      08-31-2003
The Perl Cookbook 6.23 has this "bizarre" (to me) statement;

We have found these regular expressions useful or interesting.

Turning \ followed by n into a real newline
s/\\n/\n/g;

When would a \n not be a \n ? The program below sort of simulates that condition, but presumeably there is something else?

Owen

rcook at pcug org au



#----------------------------------------------------
#!/usr/bin/perl -w

use strict;
my $string ="Now is \n the time";
print "$string\n";

$string ='Now is \n the time';
print "$string\n";

(my $newstring = $string) =~ s/\\n/\n/g;
print "$newstring\n";

Now is
the time
Now is \n the time
Now is
the time


 
Reply With Quote
 
 
 
 
Shawn Corey
Guest
Posts: n/a
 
      08-31-2003
Owen wrote:

> The Perl Cookbook 6.23 has this "bizarre" (to me) statement;
>
> We have found these regular expressions useful or interesting.
>
> Turning \ followed by n into a real newline
> s/\\n/\n/g;
>
> When would a \n not be a \n ?

# not a newline
print '\n';
# is a newline
print "\n";

 
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
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57