Using regular expressions

You can use regular expressions in text-based restrictions to search for files. For example, you can use a regular expression in the filename restriction to locate files based on one or more file extensions.

Surround SCM supports Perl-style regular expressions. The following list includes regular expression characters commonly used to match text patterns.

To match: Use: Example
Any single character . ab. matches ‘ab’ followed by any character, such as abc or ab_
Zero or one occurrences of the previous character ? colou?r matches color or colour
Zero or more occurrences of the previous character * a.* matches ‘a’ followed by any number of characters, such as ab, abb, aab, or aabb
One or more occurrences of the previous character + ba+ matches ‘b’ followed by any number of occurrences or ‘a’, such as ba, baa, or baaa
A specified number of occurrences of the previous character {...} ba{3} matches baaa
baa{3,} matches ‘b’ followed by three or more occurrences of ‘a’, such as baaa, baaaa, or baaaaa
Any single character included in a set of characters [...] [abc] matches a, b, or c
Any single character not included in a set of characters [^...] [^abc] matches any character except a, b, or c
Any single character in a specified range [ - ] [a-z] matches any lowercase character
[0-9] matches any digit, 0-9
Any single whitespace character (space, tab, new line) \s v\s matches ‘v’ followed by a whitespace character
Any single non-whitespace character \S v\s matches ‘v’, not followed by a whitespace character
Any single digit (same as [0-9]) \d v\d matches ‘v’ followed by a single digit, such as v1
Any single non-digit (same as [^0-9]) \D v\D matches ‘v’ that are not followed by a digit, such as v_

The following symbols are also helpful for creating regular expressions.

To: Use: Example
Separate two or more alternatives to perform an OR search | (gray|grey) matches gray or gray
Group several items as a single unit (...) (file1|2|3|4) matches file1, file2, file3, or file4
Escape special characters for literal interpretation (modify the meaning of the following character) \ file\.txt matches occurrences of file.txt

Examples

  • You want to send an email notification when files with the .c or .h extension are checked in to a specific branch. Use the following regular expression in the filename restriction to indicate that the trigger applies to all files with a .c or .h extension: (.*\.c)|(.*\.h)
  • You want to find all files that contain the string ‘log’ with a .doc or .xls extension. Use the following regular expression in the filename restriction: .*log.*\.(doc|xls)
  • You want to find all files that start with the string ‘log’ and include a number. Use the following regular expression in the filename restriction: log.*\d.*
  • You want to find all published web files with spaces to rename them and remove the spaces. Use the following regular expression in the filename restriction: .*\s.*
  • You want to find all files with 129 or more characters and rename them. Use the following regular expression in the filename restriction: .{129,}