Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
242 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 500 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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