Replace HTML Tags
When editing a web site, you may want to update some HTML tags to give the site a more consistent look. Let’s say some pages were created by other people, and they used slightly different text and background colors. With PowerGREP, you can easily do a search and replace to replace any <body> tag with the one you want.
- Select the files you want to search through in the File Selector.
- Make sure the file format configuration searches through the raw (unconverted) contents of HTML files. The predefined “None” configuration is one that does this.
- Start with a fresh action.
- Set the action type to “search and replace”. Leave the search type as “regular expression”.
- In the search box, enter the regular expression <BODY[^>]*> and make sure to leave “case sensitive search” off. This regular expression will match <BODY, followed by zero or more characters that aren’t a closing sharp bracket, followed by a single closing sharp bracket.
- Type the tag you want to replace all body tags with in the Replacement box. E.g.: <BODY BGCOLOR=white TEXT=black>
- Set the target and backup file options as you like them.
- Click the Preview button to run a test.
- If all looks well, click the Replace button to actually replace the tags.
Maintaining your web site is much easier with the help of PowerGREP. Most (visual) HTML editors cannot do a search and replace across all files your web site consists of. Most text editors can only search and replace literal strings, which makes it tedious to replace several styles of tags with the same tag.
You can find this action in the PowerGREP5.pgl standard library as “Replace HTML tags”.