Expressions

Use the controls on this page to edit a list of regular expressions that are used in text comparisons (including, possibly, the comparison of text files performed during a folder comparison, depending on how you have configured Merge).

Expressions are used to match unimportant text that you wish Merge to ignore when performing a comparison. This capability is useful for filtering out unimportant changes or changes that only affect the formatting within files.

Expressions List

This control contains a list of regular expressions. Only those expressions that have a check mark will be used in text comparisons.

Two types of regular expression are supported. The first enables you to force lines that contain a match for a regular expression into the unchanged state (that is, make Merge ignore those lines entirely when comparing files). This is useful for lines that contain no-other meaningful content beyond that matched by the expression. The second type of regular expression is used to ignore matching sequences of characters within a line, instead of the entire line. Double-click an item in the list to edit the expression and description fields.

Information A line matched by the first type of regular expression is shown using the fonts and colours you have configured for unchanged text. However, the linking lines relating it to text in the other file(s) are not removed and the change count shown in the status bar is not affected. The only exception to this is if every line in each of the corresponding blocks of text is matched by a regular expression. In this case, the linking lines will also be removed and the change count in the status bar will be updated accordingly.

Regular Expression Syntax

The regular expression syntax used by Araxis Merge is the same as that used by many applications in the UNIX operating system. A regular expression is a series of simple and special characters that can be used to search for sequences of characters within a piece of text.

The rest of this page contains example regular expressions. For more comprehensive information, please see the Regular Expression Reference.

Simple matches

To match lines containing the word apple:

apple

To match lines containing only the word apple:

^apple$

Matching whitespace

To match lines that are either completely empty, or that only contain whitespace (spaces and tab characters):

^[ \t]*$

Breakdown:

  • ^ Match the start of the line.
  • [ \t]* Match zero or more space or tab (\t) characters.
  • $ Match the end of the line.

Matching C++ comments

To match lines that contain only a C++ style comment (//, followed by any characters up to the end of the line), the following expression can be used:

^[ \t]*//.*$

Breakdown:

  • ^ Match the start of the line.
  • [ \t]* Match zero or more space or tab (\t) characters.
  • // Match two consecutive / characters.
  • .* Match zero or more occurrences of any character.
  • $ Match the end of the line.

Matching source code control keywords

Some version control products enable special keywords to be inserted into text files. Subversion, for example, will expand out a piece of text $Date$ so that it contains the date and time of the last check-in. When comparing different revisions of a file, lines containing these keywords will almost always be different and can be ignored. An expression to ignore the Date keyword when it appears in C++ comment lines follows:

^[ \t]*//.*\$Date:.*\$.*$

Breakdown:

  • ^ Match the start of the line.
  • [ \t]* Match zero or more space or tab (\t) characters.
  • // Match two consecutive / characters.
  • .* Match zero or more occurrences of any character.
  • \$ Match the character $, not the end of line. Putting \ before a character means that the character is treated as literal. Any special meaning it might have had as a regular expression is removed.
  • Date: Match Date:
  • .* Match zero or more occurrences of any character.
  • \$ Match the literal character $.
  • .* Match zero or more occurrences of any character.
  • $ Match the end of the line.

Related expressions:

  • ^[ \t]*//.*\$Archive:.*\$.*$
  • ^[ \t]*//.*\$Author:.*\$.*$
  • ^[ \t]*//.*\$Header:.*\$.*$
  • ^[ \t]*//.*\$JustDate:.*\$.*$
  • ^[ \t]*//.*\$Modtime:.*\$.*$
  • ^[ \t]*//.*\$Revision:.*\$.*$
  • ^[ \t]*//.*\$Workfile:.*\$.*$

Combining expressions

Several expressions can be combined in to one by using the parenthesis () and | characters:

(apple|^pear$)

Breakdown:

  • ( Begins a group of expressions.
  • apple Match lines containing the word apple.
  • | Match lines that contain matches for the previous expression (apple) or the next one (^pear$).
  • ^pear$ Match lines consisting of only the word pear.
  • ) Ends the group.

This syntax enables larger expressions like the following to be constructed:

^[ \t]*//.*\$(Date|Archive|Author|Header|JustDate|Modtime|Revision|Workfile):.*\$.*$

It is almost always better for comparison performance if expressions are made as short as possible. The example above is significantly better than the following:

(^[ \t]*//.*\$Date:.*\$.*$)|
(^[ \t]*//.*\$Archive:.*\$.*$)|
(^[ \t]*//.*\$Author:.*\$.*$)|
(^[ \t]*//.*\$Header:.*\$.*$)|
(^[ \t]*//.*\$JustDate:.*\$.*$)|
(^[ \t]*//.*\$Modtime:.*\$.*$)|
(^[ \t]*//.*\$Revision:.*\$.*$)|
(^[ \t]*//.*\$Workfile:.*\$.*$)