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
200 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

23 Experts available now in Live!

Get 1:1 Help Now