[thelist] Learning Regular Expressions

Michael Barrett mbarrett at triad.rr.com
Sun Oct 14 18:24:30 CDT 2001


Wow. What a handy thing, the regular expression.

Some time back I posted a response to DaList offering a regular expression
(or grep) as an alternative to cleaning out some tags in html documents
using Dreamweaver's Search and Replace dealy.

Naturally within moments other listees had posted better, purtier, more
powerful greps.

I've added these to my arsenal in a handy text file I keep open while
working.
(a good deal of my recent work has been the updating and facelifting of old
academic websites. Sloppy is an understatement.)

So my question is:
Where does a brother go to learn how to really understand, use, and write
regular expressions well?

<tip type="html clean up with Regular Expressions in Dreamweaver"
author="Michael Barrett">
Need to remove a ba-zillion font tags from an old HTML document?
Try a Regular Expression.
Regular Expressions are patterns of text that can be used to find repeated
text snippits which exhibit some regularity e.g. Many of the same html
element/tag with varying attributes. All font tags will include a "<", maybe
a "/" if it's the end tag, a "font" or a "FONT", and perhaps some size="blah
blah" attribute. The elements that are common to all font elements are
enough to distinguish all font tags from the rest of the HTML document.

Using "Search and Replace" from the edit menu, click "Use Regular
Expressions" below the "Replace with" text box.

To remove all instances of a font tag with any attributes, enter this in the
search box:
<[\/]*font[^>]*>

To remove just the start tag from a font element:
<font[^>]+>

To strip the style attributes from tags:
 style="[^"]*"
(note the leading space)

Of course you can replace "font" with any tag you'd like to remove.
Likewise, you can replace "style" with any attribute you'd like to remove.

Leave the "Replace" field blank. Click "Replace All"

In Dreamweaver, you can select the entire site folder in the site window,
then apply this search and replace to every html document in the site, thus
stripping away useless font tags in one quick step.
</tip>


-- 
Michael Barrett
-O^O-
  - 

mbarrett at triad.rr.com
AIM: device55





More information about the thelist mailing list