Accessibility

Table of Contents

Introduction to Regular Expressions in Dreamweaver

Matching Closing Tags Using an Optional Character

So far, you've succeeded in creating a regular expression that matches all beginning HTML tags (except for the <meta> tag), but not the closing tags. In HTML, a tag is closed by creating a second, matching instance of the tag with one slight difference: the beginning less-than sign is followed by a forward slash. For example, the beginning tag is <body> and the closing tag is </body>.

As I mentioned earlier in this article, an optional character is represented by the question mark. You will now update your regular expression to allow for an optional forward slash so that it matches either an opening HTML tag or a closing HTML tag.

</?[A-Za-z]+>

The regular expression now reads as "match a less-than sign followed by an option forward slash and then by any one or more of the range of characters listed inside of the brackets until a greater-than character is found."

As before, try searching on this extension and you'll see that both beginning and ending tags are found. You're making progress, but you're still not matching the <meta> tag since the regular expression is not flexible enough to match attributes and values.