Regex problem

V

Vito Corleone

Hi,

How can I change every:
<photo src=111:123:456> to
<img src=img/111/123/456>?

I tried:
$html =~ s#<photo src=($d+):($d+):($d+)>#<img src=img/$1/$2/$3>#g;

But there is a possibility that there is a newline in it. Is there any
better way to change this?
 
K

kenneth

Vito said:
Hi,

How can I change every:
<photo src=111:123:456> to
<img src=img/111/123/456>?

I tried:
$html =~ s#<photo src=($d+):($d+):($d+)>#<img src=img/$1/$2/$3>#g;

But there is a possibility that there is a newline in it. Is there any
better way to change this?
are you sure where did the newline would appear?
 
V

Vito Corleone

Hi Kenneth,
are you sure where did the newline would appear?

No it could be anywhere. Actually I make this for online BBS, where user
can choose an icon, click on it, and the javascript will put <photo
src=12:13:14> on the text. I would be easier if I put <img
src=img/12/13/14.gif> on the first place, but some user has different
directories, so I have to get_user_id, and then change <photo src> to
appropiate <img src>.
 
I

ioneabu

Vito said:
Hi Kenneth,


No it could be anywhere. Actually I make this for online BBS, where user
can choose an icon, click on it, and the javascript will put <photo
src=12:13:14> on the text. I would be easier if I put <img
src=img/12/13/14.gif> on the first place, but some user has different
directories, so I have to get_user_id, and then change <photo src> to
appropiate <img src>.

try this first:

$html =~ s/\n//g;

then your thing:

$html =~ s#<photo src=($d+):($d+):($d+)>#<img src=img/$1/$2/$3>#g;
maybe that will help with the newlines.
 
T

Tore Aursand

Vito said:
How can I change every:
<photo src=111:123:456> to
<img src=img/111/123/456>?

I tried:
$html =~ s#<photo src=($d+):($d+):($d+)>#<img src=img/$1/$2/$3>#g;

But there is a possibility that there is a newline in it. Is there any
better way to change this?

Get rid of the newline(s) first;

$html =~ s,\n,,g;
$html =~ s,<photo src=(\d+):(\d+):(\d+)>,<img src=img/$1/$2/$3>,g;
 
K

kenneth

Vito said:
Hi Kenneth,




No it could be anywhere. Actually I make this for online BBS, where user
can choose an icon, click on it, and the javascript will put <photo
src=12:13:14> on the text. I would be easier if I put <img
src=img/12/13/14.gif> on the first place, but some user has different
directories, so I have to get_user_id, and then change <photo src> to
appropiate <img src>.
o,i'm not fimilar with html,and doubted the photo line will lost its
value whether the newline appear everywhere. maybe.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,166
Messages
2,570,907
Members
47,446
Latest member
Pycoder

Latest Threads

Top