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
221 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dreamweaver css dropdown will not show styles 8 701
Why am I not able to make changes on my local machine to a website? 6 334
Edit Muse Website with Dreamweaver 6 1,311
Need icon art 9 117
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…
I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …

791 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