[tpm] New Regex question

Chris Jones cj at enersave.ca
Tue Oct 30 05:47:10 PDT 2012


>
>
>You don't need \r\n ... \n is sufficient:
>
>       "\n matches a logical newline. Perl converts between \n and your
>        OS's native newline character when reading from or writing to text
>        files."
>                   'Character Escapes'
>                   in 
> <http://perldoc.perl.org/perlrebackslash.html>http://perldoc.perl.org/perlrebackslash.html
>
>Also, do you want to wind up with either a space or a newline, 
>accidentally, depending on which one came first?
>
>Consider       "line 1 \n \nline 3" collapsing into "line1 line 3"
>compared to "line 1\n \nline 3"  collapsing into "line1\nline 3"
>just because of a trailing  space.
>

Apparently Microsoft didn't inform Perl that the access database uses 
\r\n in the memo field.
$exp =~ s/(\s|\n)\1+/$1/g;
"Expression 1:","if(Local(TYPE) == 1) then
   1.25

else
   UNCHANGED
endif",

"Expression 2:","if(Local(TYPE) == 1) then
  1.25

else
  UNCHANGED
endif"

Adding the \r produces the desired output:
s/(\s|\r\n)\1+/$1/g;
"Expression 1:","if(Local(TYPE) == 1) then
   1.25

else
   UNCHANGED
endif",

"Expression 2:","if(Local(TYPE) == 1) then
  1.25
else
  UNCHANGED
endif"

 >>
Christopher Jones, P.Eng.
Suite 1801, 1 Yonge Street
Toronto, ON M5E1W7
Tel. 416-203-7465
Fax. 416-946-1005
email cj at enersave.ca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20121030/b4d944b5/attachment.html>


More information about the toronto-pm mailing list