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
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
submit button form code 2 438
Software Tool for cleaning up UNUSED WEB FILES ? 2 279
Adobe Photoshop CC 2015 action script help 2 233
Adobe Acrobat Pro: Is this a known bug? 9 143
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 …
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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