HOWTO: Search And Replace Text Using Regular Expressions
To find file(s) containing the text that matches a pattern and replace the text in
them, do the following.
- Specify the folder in which you want to find files. For example:
C:\MyWebFiles\Projects
- Set mask(s) of the files that you want to find. For example:
*.htm*;*.asp;*.cpp
- Provide the pattern in the Find What field for the matching text that you want to find.
For example, you want to replace the CENTER value of the ALIGN
attributes with LEFT in all <TABLE>
tags in HTML files. The corresponding pattern would include:
- the opening tag -
\<;
- tag name (
TABLE);
- as the tag may contain other attributes, some wildcard operator and
repetition operator enclosed in the expression operator for
further reference -
(.#);
- ALIGN attribute and a value -
ALIGN\=CENTER;
- as the tag may contain other attributes after ALIGN, some wildcard operator and
repetition operator enclosed in the expression operator for
further reference -
(.#);
- the closing tag -
\>.
The pattern in this case would look as follows:
\<TABLE(.#)ALIGN\=CENTER(.#)\>
- Provide the replacement expression, where \1 and \2 stands for the previously
remembered parts of text
(.#):
\<TABLE\1ALIGN=LEFT\2\>
- If you want to first see what you will replace, click the Search button.
- Make sure the option Search only is unchecked.
- Click the Replace button.