PERL Search & Replace

W

Walt

In the following single line @URLs will contains all urls from $omsg.

@URLs = ($omsg =~/(\Shttp:\/\/| http:\/\/|\shttp:\/\/)(.*?)(<br>|\n|\r|
)/gi);

What I would like to have is a way to scan in the same line if there
is an equal sign in front of http and if so, omit it.

Is there a way to do it within the single line?
 
D

David Squire

Walt said:
In the following single line @URLs will contains all urls from $omsg.

@URLs = ($omsg =~/(\Shttp:\/\/| http:\/\/|\shttp:\/\/)(.*?)(<br>|\n|\r|
)/gi);

What I would like to have is a way to scan in the same line if there
is an equal sign in front of http and if so, omit it.

Is there a way to do it within the single line?

It is not clear if you mean directly in front, e.g. '...=http', or if it
can be anywhere in front. The or'ing of '\S', ' ', and '\s' looks very
odd: surely \S or'ed with \s matches everything, and ' ' is a subset of
'\s'. Some sample data would make the question clearer.

Still, this should do the trick:

@URLs = ($omsg =~/[^=](http:\/\/)(.*?)(<br>|\n|\r|)/gi);

(untested, as I can't know what your data is actually like).

For future reference: perldoc perlre

Regards,

DS
 
C

ClubK

So, @URLs = ($omsg =~/[^=](http:\/\/)(.*?)(<br>|\n|\r|)/gi); should
give me all urls that do not start with equal sign directly in front of
http?

Thanks for the reply. I titled the first post wrong deleted it and
changed the tile. Sorry about that.

I am very new at alot of this so some of my code practice is
experimental.

I am using this line to auto link urls in my forum so people don't
have to. Convert the plain text http://www.clubknowledge.com to a
clickable link but not a href=http://
 
D

David Squire

ClubK said:
So, @URLs = ($omsg =~/[^=](http:\/\/)(.*?)(<br>|\n|\r|)/gi); should
give me all urls that do not start with equal sign directly in front of
http?

Yep. Reading the manual will make that clear: perldoc perlre

[snip]

Please quote context and give attribution to its author when posting on
Usenet. Read and follow the practices described at
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html to get the
most out of this (and other) newsgroups.

DS
 

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
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top