Re: Need regexp to rejoin URL links broken by \n



In article <1119431715.381879.27690@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Tony <hawkmoon1972@xxxxxxxxxxx> wrote:

: Can someone help me with a regular expression that removes \n's from
: the middle of URL's?
: [...]

My first thought was to suggest stripping all runs of whitespace and
feeding the result to URI::Find, but then I realized that you're
trying to reformat the message for human consumption.

Below is a cut at it:

$ cat try
#! /usr/local/bin/perl

use warnings;
use strict;

chomp(my $A = <<EOMessage);
Hello, this is an
email which has
been formatted to
fit a narrow
column. Here is a
URL: http://test.
com/hello?test=op
tion1&test2=optio
n2. Thanks for
reading.
EOMessage

$A =~ s!(http://.+?\.) !($a=$1) =~ tr/\n//d; "$a\n"!se;

print $A, "\n";

$ ./try
Hello, this is an
email which has
been formatted to
fit a narrow
column. Here is a
URL: http://test.com/hello?test=option1&test2=option2.
Thanks for
reading.

Using /\. / as a terminator strikes me as being *very* brittle, but
that only shows the truth of mjd's words: "Of course, this is a
heuristic, which is a fancy way of saying that it doesn't work."

Hope this helps,
Greg
--
It should be noted that government is never so zealous in suppressing
crime as when that crime consists of direct injury to its own sources of
revenue, as in tax evasion and counterfeiting of its currency.
-- Murray Rothbard
.



Relevant Pages

  • Re: Chanakyas Quotes - Worth reading a million times…
    ... yes, reading is not enough. ... are many - but let's ask who does fit the profile of an ideal ... question is would india elect him as its pm? ... tango partner Blue Turban Singh may not have even heard of Chanakya, ...
    (soc.culture.indian)
  • Re: 98 HR MH was Janets 2004 Allegro Bay 37 DB
    ... Keeping up with reading this newsgroup is what got me to ... finally look around here for something that can fit into a small ... Japanese parking space. ... quilt while staying in a state forest for a week. ...
    (rec.outdoors.rv-travel)
  • Re: Ot: Winter Reading-what are you reading
    ... Not fit for man nor beast. ... - among his many discoveries was Laughing Gas, kinda fits don't ... > What ya reading while ya smoke ASP? ...
    (alt.smokers.pipes)
  • Re: Civil / Annihilation War
    ... Nathan P. Mahney wrote: ... I haven't been reading any of it, but got the impression Beyond was ... How does it fit with current Spider-Man continuity? ...
    (rec.arts.comics.marvel.universe)
  • Re: Cast from string to type integer
    ... Reading and reading again I get the idea that you have more tables which ... (How it will fit, is for me something impossible however let us asume it ... It is not impossible that with some clever ... Because as I read it is there in fact no logical relation however a phyiscal ...
    (microsoft.public.dotnet.framework.adonet)