Filtering out text

When comparing several files, you may have sections of text where differences aren't really important. For example, you may want to focus on changed sections of code, and ignore any changes in comment lines. With text filters you can tell Meld to ignore text that matches a pattern (i.e., a regular expression) when showing differences between files.

Text filters don't just affect file comparisons, but also folder comparisons. Check the file filtering notes for more details.

Adding and using text filters

You can turn text filters on or off from the the Text Filters tab in Preferences dialog. Meld comes with a few simple filters that you might find useful, but you can add your own as well.

In Meld, text filters are regular expressions that are matched against the text of files you're comparing. Any text that is matched is ignored during the comparison; you'll still see this text in the comparison view, but it won't be taken into account when finding differences. Text filters are applied in order, so it's possible for the first filter to remove text that now makes the second filter match, and so on.

If you're not familiar with regular expressions, you might want to check out the Python Regular Expression HOWTO.

Getting text filters right

It's easy to get text filtering wrong, and Meld's support for filtering isn't complete. In particular, a text filter can't change the number of lines in a file. For example, if we had the built-in Script comment filter enabled, and compared the following files:


then the lines starting with b would be shown as identical (the comment is stripped out) but the d line would be shown as different to the comment line on the right. This happens because the #comment is removed from the right-hand side, but the line itself can not be removed; Meld will show the d line as being different to what it sees as a blank line on the other side.

Blank lines and filters

The Ignore changes which insert or delete blank lines preference in the Text Filters tab requires special explanation. If this special filter is enabled, then any change consisting only of blank lines is completely ignored. This may occur because there was an actual whitespace change in the text, but it may also arise if your active text filters have removed all of the other content from a change, leaving only blank lines.

You can use this option to get around some of the problems and limitations resulting from filters not being able to remove whole lines, but it can also be useful in and of itself.