Solved

Want to use FIND AND REPLACE with REGULAR EXPRESSIONS for parsing a nonlink and making it a link

Posted on 2004-10-11
6
209 Views
Last Modified: 2012-03-15
Hopefully my title wasn't too confusing

Basically, I have alot of text I am pasting into the source code of dreamweaver because I have to format it appropriately.

Well, basically its a large list of companies and their website addresses. Except, in the code, its just

www.whatever.com 

So I might have

Company Name<br />
Company Description<br />
www.companyurl.com

except it doesn't have the <a href="http://  added to the front, nor does it have the closing </a>.

It would be great, however, if there was a regular expressions that would go through my source code and find the

www

and add onto the front an      <a href="http://    , then close the link with  ">, then allow for the www.companyurl.com to be the linked text, and then close it using </a>

Is this possible?  If so, what is the regular expression to do so?

Thanks
Bryan
0
Comment
Question by:jag5311
6 Comments
 
LVL 8

Expert Comment

by:alexhogan
ID: 12286927
For your regular expression try this;

^(([-!#\$%&\'*+.0-9=?A-Z^_`a-z{|}~^?]+\.)+[A-Za-z]{2,6})(\:[0-9]+)?(/)?/
0
 
LVL 10

Expert Comment

by:Havin_it
ID: 12288153
Hi Jag,

The difficulty is that DW's Find/replace function can't add the prefix and suffix to  the string you are searching for. In fact, by searching for a string, all you can do is replace it with another string (and if you go through the whole site, every string will be replaced with that - you can't preserve the contents of the search-string.

What you can do is exploit this forum's (or some others') scripting to do the job for you. A lot of web forums use scripts to turn URLs they find in your posts into active hyperlinks. I won't claim to know how they do it, but you can either abuse this or another forum, or if you have access to a PHP/MySQL enabled webserver, you can install phpBB

phpBB
Makes a bulletin board application (free!)
www.phpbb.com

and do it for yourself. Simply copy the text from the web page out of your browser, paste it and submit it as a post.  When your post is displayed (live links and all) simply view the source and copy it into your page. Can't do the whole site at automatically, but still pretty efficient!

PS - Seriously, don't do it here. It will cost you a lot of points and maybe a ban. Find a phpBB-powered dev forum (they tend to look quite similar) and ask permission there.
0
 
LVL 1

Accepted Solution

by:
chief77 earned 125 total points
ID: 12316692
in dreamweaver you can use RegEx grouping, then use $1 to recall the group for substitution (when replacing)

first of though, does all the non-link text have www. in front? if so, you can try this
search for: (www\..+)
replace with : <a href="http://$1">$1</a>

JUST BE CAREFUL not to run the find and replace the twice, as it will pick up the linked text. OR just do an one-by-one find and replace and not the "replace all"..

hope that help.

Kel.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:chief77
ID: 12316710
oh code explanation:

(www\..+) -- this pattern is to look for a group with "www" then "\." is the actual "." and the ".+" is any character one or more times.

which will fit our www.microsoft.com where the "www." is covered by "www\." and "microsoft.com" covered by ".+"


then the <a href="http://$1">$1</a> well.. the usual <a href=...>, the "$1" is recalling the value from our pattern group (www\..+) -- anything inside the () is a group.

Kel.
0
 
LVL 1

Expert Comment

by:chief77
ID: 12336164
Hello, have you given my suggestion a try?

Kel.
0
 

Author Comment

by:jag5311
ID: 12352176
Hey Kel,

Geez, I am sorry. When I signed up for this forum, I was still in college. But I have graduated and forgot to change my email so I don't get updates (until today :))

I had to manually change everything.

It wasn't too hard, I used find and replace, but did it the slow way.

I wish I would have given your option a shot.

I will save it though for a rainy day.

You get the points.

Thanks
Bryan
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now