Articles

dw-cs4-01

Regular Expressions with Find & Replace in Dreamweaver

The Problem

Note: This example was performed in Dreamweaver CS4 on Windows and has not been tested in other versions or on other platforms.

Need to remove all META Keywords from all pages of a site, in line with Google’s recent decision to penalise against their use. Several sites affected, one of which has around 650 pages. Conventional find and replace will not work because each page contains different keywords so no regular match will be found.

The Solution

Check the ‘Use regular expression’ box in DW’s Find and Replace dialog, then enter the following text in Find, nothing in Replace and click Replace All:

<meta name=”keywords” content=[wW]*?>

The regular expression component of this search string is the [wW]*? part, so in this case it will find any instance of the keywords meta tag, regardless of content. Supplying nothing for the Replace string results in the line being removed in its entirety, regular expressions also allow us to impose uniformity by replacing variations with specific text across the whole site, or in selected files or folders.

These regular expression are of the similar (perl) type used in PHP, Javascript and other languages.

Tips

  • Always take a full backup before this kind of bulk update
  • Test on a small number of files first
  • ‘Ignore whitespace’ should be checked for most find and replace operations, ‘Match case’ generally will not be

Links