CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
help with regular expression

 



jck7777
New User

Jan 9, 2004, 10:43 AM

Post #1 of 3 (3419 views)
help with regular expression Can't Post

  $Form{$sorted_field} =~ s/\r\n/\s/g;


I expected this expression to replace newline characters with whitespace. What it does is replace newline characters with an s. So I thought, perhaps I should escape the "\s" special character with another \, that just replaces the newline characters with a \ and an s.

Thanks in advance smart people.


davorg
Thaumaturge / Moderator

Jan 10, 2004, 11:36 AM

Post #2 of 3 (3417 views)
Re: [jck7777] help with regular expression [In reply to] Can't Post


In Reply To
$Form{$sorted_field} =~ s/\r\n/\s/g;

I expected this expression to replace newline characters with whitespace. What it does is replace newline characters with an s. So I thought, perhaps I should escape the "\s" special character with another \, that just replaces the newline characters with a \ and an s.


\s stands for a whitespace character in a regular expression. The right hand part of the substitution operator (the replacement string) is _not_ a regular expression, it's treated as a double-quoted string. Therefore you can't use regex escape sequences in the replacement string.

Just use whatever character you want the replacement to be.


Code
$Form{$sorted_field} =~ s/\r\n/ /g;


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


jck7777
New User

Jan 12, 2004, 4:06 PM

Post #3 of 3 (3412 views)
Re: [davorg] help with regular expression [In reply to] Can't Post

Thanks for the assistance.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives