
Dreamweaver has a powerful search/replace ability which includes ‘regular expressions’. This allows you to scan and replace particular html without affecting data.
Here’s an example of how useful this is:
Let’s say you are harvesting content from Wikipedia and putting it on your own website. Though I don’t endorse that activity, it is allowed according to the GDFL and a lot of people do it. So, here’s a way to make it easy.
Let’s say you find a huge table full of data that you wish to use on your own website. Since Wikipedia has tons of links and junk in the code, you want to strip it all out. One way is to copy and paste into Excel, then save as a .csv or .txt file, thus stripping out the extra invisible formatting html code that was previously a part of it. Then, close and re-open the .csv or .txt into Excel, then copy and paste into Dreamweaver (or your HTML editor). While this works, Excel still seems to copy over some html formatting, such as <td height="17" … on every field of the table, which is annoying.
You can do a find/replace in Dreamweaver for height=”17” and leave the replace field blank. That would solve that problem, however, Wikipedia often uses footnotes which add [1] [2] [3] etc in superscript, such as the example below. The question is how do we delete these brackets from our copied table, but preserve the data. Good news- we can do that with Dreamweaver, using regular expressions.
Change from this:
<td height="17">Batman Begins[1][2]</td>
<td height="17">Superman</td>
<td height="17">Army of Darkness[3]</td>
Into this:
<td>Batman Begins</td>
<td>Superman</td>
<td>Army of Darkness</td>
If you had a huge table full of this with 100+ rows with 50 or more footnotes, it would take a long time to manually remove all of the brackets by hand. Here’s a way to automate it in Dreamweaver:
(Make sure you are searching the ‘source code‘ and that the ‘Use regular expression’ box is checked)
Find:
<td height="17">([^<]*)\[[^"]*</td>
Replace:
<td>$1</td>
Result:
Dreamweaver will instantly strip out all the junk from your code and replace it with the core code while preserving your data. In this case, the wildcard variable will preserve anything between <td height="17"> and </td>.
Explanation:
The find is the prefix of the tags, then the wildcard variable that’s stored: ([^<]*) then, I wanted to remove the brackets, so I put one in, but since we’re using expressions, it has to be ‘escaped’ to tell it we literally mean the bracket, so I put this \ before the [ then I added a non-stored wildcard variable (the other junk I want removed), so I added: [^"]* then the close tag </td>. Then the replace is the simple $1 variable between the tags which recalls the stored variable. Very cool!
Another challenge:
Let’s say you want to copy a huge list of links from Wikipedia and change them to our own links on our own website. Here’s an example:
Change from this:
href="/wiki/Army-of-Darkness">
href="/wiki/Raiders-of-the-Lost-Ark">
href="/wiki/Pulp-Fiction">
Into this:
href="http://www.domain.com/Army-of-Darkness.php">
href="http://www.domain.com//Raiders-of-the-Lost-Ark.php">
href="http://www.domain.com/Pulp-Fiction.php">
In Dreamweaver, select Find/Replace…
1. Check ‘use regular expression’
2. Do Find for:
href="/wiki/([^<]*)">
4. Replace:
href="http://www.domain.com/$1.php">
5. It preserves the variable inside
Without the regular expression, you could have done Find/Replace for the first part, but when you wanted to add the .php to the end, you’d be stuck. How else would you do it?
Pretty incredible, huh? You can automate the changing of links or anything on an entire website with thousands of links and pages in just seconds. All using the stored wildcard variable.
([^<]*) is stored (use $1 to retreive in replace)
[^"]* is unstored
You can also do Find/Replace to recall multiple variables at once, like this:
If multiple wildcards:
([^<]*) ([^<]*) ([^<]*)
Use:
$1 $2 $3
A tool like this can give you the power to harvest public domain or free content, manipulate data and repurpose it for your own site.
Hi,
This is my fist attempt with RegularExpression.
Do somebody know how to replace multiple characters in Dreamweaver?
I search for ([\—\–\”\“\‘\’]) And woul like to replace these characters with – ” and ‘.
I know how to search for them but i have no idea what to enter in the replace form.
Thankfull for all the help i can get
// Daneil
for this:
href=”/wiki/Army-of-Darkness”>
href=”/wiki/Raiders-of-the-Lost-Ark”>
href=”/wiki/Pulp-Fiction”>
to change into this:
href=”http://www.domain.com/Army-of-Darkness.php”>
href=”http://www.domain.com//Raiders-of-the-Lost-Ark.php”>
href=”http://www.domain.com/Pulp-Fiction.php”>
you do like this:
1. find: href=”/wiki/ and replace with href=”http://www.domain.com/
2. find: “> and replace with: .php”>
Of course, prior this you’ll have to have only this code on the page to do not mess up other closing tags from the document.
Thanks for tips!
Thank you so much!! You just saved me a huge amount of manual editing.
I had a table with tr tags that each were unique to indicate row # and <tr class="row 2". I wanted them all to just be . I took your expression and inserted it <tr class="([^ and did not include the $1 since I didn’t want to preserve anything. I just replaced with and it worked!!
I had problems because I switched from golive ro dreamweaver. I had some mistakes using the simple top-links. So I wanted to correct al the links (about 1000) witch pointed to each page. I wanted to keep them simple.
and more
I wanted to changed them all to
1. At first I took your example: <a href="([^
so I got
2. Then I changed (using the normal find and replace mode) to
finished
As a beginner I never worked with wildcards and regular expressions. I even didn’t know about them 2 houres before. All information I found in the web where confusing to me.
So Dear Trent thank you a lot for your tutorial and especially for showing some examples which where very helpfull to me.
Trent Please delete my last posts
Dear Trent,
I had problems because I switched from golive to dreamweaver. I had some mistakes using the simple top-links. So I wanted to correct all the links (about 1000) witch pointed to each page. I wanted to keep them simple.
I had links like:
href=”/abstehende-ohren.html#top”>
href=”/brustverkleinerung.html#top”>
And so on
I wanted to change them to
href=”# “>
Some hours before I had never heard about regular expression an wildcard. But fortunately I found your site (the other sites I found where not very useful for a beginner like me
). So I could use your tips.
At first I searched for
href=”([^
And changed it to
href=”#top”>
Then I searched for all href=”#top”>
and replaced it with
href=”#”>
Thank you a lot for your tutorial
Bye, René
I have over a thousand pages with a variable string like this:
page #1 <a href="http://www….com/product/01039485692?tag…...
page #2 <a href="http://www... .com/product/0593938643?tag……
I want to find and replace all the pages but each string has different numbers in it, the rest of the string is the same.
I want to replace all those different strings with this:
Our Discount Price
Any help is appreciative
Bill
You can do this with Dreamweaver and regex. My page here is not comprehensive, do a search and you’ll find a good guide. This site might work ok: http://www.regular-expressions.info/reference.html
This is fantastic stuff and will really help me, if I can figure out how to use it.
I have a few (but only a few) times had success.
It says to “Use regular expression.” What does that mean? What is an “irregular expression?” I have tried with the box checked and unchecked. Usually with the box checked it will not Find my string. I uncheck the box and it usually does.
I am posting an example on the above website.
From the DW source code I literally copy the line of code:
Joh. Heinrich Schöm (1713-1785) 1.
and paste it into the Find box of F&R. I then put my cursor above the line and it does not Find it, giving me the “Done. Not found in current document.” response. I uncheck the “Use regular expression” box and it will find it as long as there is no wildcard. It finds it in all four (identical) examples.
THEN,
I try using a wildcard (with the box checked), Finding:
([^<]*)
or
[^”]*
and it will find the misc. lines, e.g. where the text is “Case #1”, but not the lines of interest, with Heinrich’s name. With the box unchecked it Finds nothing.
Really would appreciate help. Thanks.
Hi, I want to remove everything before @ from emails addresses, i.e. my.address123_O@yahoo.com
How can this be done in Dreamweaver?
Thanks, this article is awesome!
In your regex code, you might try using ^\s which should literally mean ‘find anything, except a space (continuous characters before the @ sign)’
So, to remove prefixes of emails, try searching:
([^\s]*)@
then replacing with:
@
This is the other way people can search/match emails:
^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$
good ! tutorials , very helpful………………….
one question is in my mind how to replace a word e.g ‘name’ by ‘name1′ , ‘name2′ , ‘name3′ ………………….in documents where is find.
please help
Thanks