PDA

View Full Version : help me with perl regexp



tisungho
November 26th, 2010, 12:52 PM
Hi

I want to replace the second value of "10-11-25" (in bold font) to "-":

<TD><FONT SIZE=-1><A HREF="10-11-25/all_runs.html">10-11-25</A></FONT></TD>

For example, the final result should look like this:
<TD><FONT SIZE=-1><A HREF="10-11-25/all_runs.html">-</A></FONT></TD>

Here is my solution:
$line is above string

$line=~s/(\d+)/-/g

But the result is like this :(
<TD><FONT SIZE=--><A HREF="-----/all_runs.html">-----</A></FONT></TD>

Please help me!

Thanks!

Arndt
November 26th, 2010, 01:13 PM
Hi

I want to replace the second value of "10-11-25" (in bold font) to "-":

<TD><FONT SIZE=-1><A HREF="10-11-25/all_runs.html">10-11-25</A></FONT></TD>

For example, the final result should look like this:
<TD><FONT SIZE=-1><A HREF="10-11-25/all_runs.html">-</A></FONT></TD>

Here is my solution:
$line is above string

$line=~s/(\d+)/-/g

But the result is like this :(
<TD><FONT SIZE=--><A HREF="-----/all_runs.html">-----</A></FONT></TD>

Please help me!

Thanks!


$line=~s/\[B\]10-11-25\[\/B\]/-/

tisungho
November 26th, 2010, 03:26 PM
$line=~s/\[B\]10-11-25\[\/B\]/-/

Hi,
Thanks for your help, but it doesn't work :(
And also, we shouldn't hardly match it like this way, because the date is gonna be changed

DaithiF
November 26th, 2010, 03:31 PM
$line=~s/>\d{2}-\d{2}-\d{2}</>-</g;

Arndt
November 26th, 2010, 03:32 PM
Hi,
Thanks for your help, but it doesn't work :(
And also, we shouldn't hardly match it like this way, because the date is gonna be changed

It worked when I tried it. What does it do?

When the date changes, you of course change the numbers to something more general.

Arndt
November 26th, 2010, 03:38 PM
Hi,
Thanks for your help, but it doesn't work :(
And also, we shouldn't hardly match it like this way, because the date is gonna be changed

I think I know what happened: your bold marks got into my expression. Just remove them.