[Israel.pm] A simpler regex required

Peter Gordon peter at pg-consultants.com
Tue Aug 14 07:22:05 PDT 2007


Hi. 

Let's suppose that I have the following lines in an HTML file. 
I want to substitute the spaces in the date part with non-breaking spaces ( )

<td  style="text-align: left" bgcolor="#92c1bb">Aug 12 23:59:59 2007 GMT</td>
<td  style="text-align: left" bgcolor="#92c1bb">Aug 12 23:59:59 2007 GMT</td>

I came up with this line - but somehow it isn't aesthetic.

s!(<td.*?>)(.*?)(</td>)!my $t1 = $1 ;my $t2 = $2 ; my $t3 = $3 ; $t2 =~ s/\s/&nbsp;/g ; "$t1$t2$t3" ;!egs ;

Is there a nicer/cleaner way to write it?

Peter




More information about the Perl mailing list