Wednesday, September 8, 2010

Regular Expression Search and Replace

Using Textpad's implementation of RegEx, the following will find all closing HTML/XML tags and add a carriage return after them:

search:  </[^>]*>
replace: \0 \n


Same thing, to create a carriage return before starting tags:

search:  <[^>]*>
replace: \n \0

This really helps when you are trying to view HTML that has been machine generated and appears in a single line.

Where Textpad uses the backslash (\) for the replacement sytax, other implementations of RegEx use the percent symbol (%).

No comments: