Forum Moderators: coopster & phranque

Message Too Old, No Replies

perl pattern matching

I can't figure out what part of the pattern I'm getting wron

         

jeremy goodrich

1:02 am on Apr 16, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is the string I'm trying to replace:

\<td height\=\"344\" bgcolor\=\"\#000024\" width\=\"699\" bordercolor\=\"\#000024\" rowspan\=\"2\"\>

with this one:

\<td height\=\"344\" bgcolor\=\"*\" width\=\"728\" bordercolor\=\"*\" rowspan\=\"\2\"\>

Problem is, I need this across multiple files, so I need to be able to change the td height and width to just a three character match, and leave the actual numbers alone.

I've tried changing to \d\d\d for the 3 characters, and some other stuff, but it's not working. Any and all comments or help greatly appreciated!!

theperlyking

1:28 am on Apr 16, 2001 (gmt 0)

10+ Year Member



I'm not strong on this but would this work?

$original =~ s/width\=\"\d{3}\"/width\=\"\728\"/;

jeremy goodrich

2:52 pm on Apr 16, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So you're saying that matching the \d{3}\ would match the 3 digit string...good.

Will this leave that namespace unaltered? I mean, I need to replace the parts of the string with the color, and leave the rest along. And since some of the files are different size tables, etc. I need to preserve the formatting.

I'll give that a shot. I will need to match the \d{3}\ 3 digits, and replace them with the same three digits. So put this in on the find and replace strings?

theperlyking

3:53 pm on Apr 16, 2001 (gmt 0)

10+ Year Member



Yep, \d{3} is to match 3 digits.
The formatting would stay the same.

To replace colour it would be something like
$original =~ s/bgcolor\=\"\#.{6}\"/bgcolor\=\"\#ffffff\"/;