Redirections using regular expression (Regex) pattern matching

17/09/2018 Stuart Moore

Redirections and Regular Expressions 

File redirection rules support regular expressions to help reduce the number of redirections required for Containers. The ability to specify wildcards makes it far easier to redirect all of the application data to user's profile location, or away from the Container if you want to deploy read only Containers on your desktops and servers.

Exact matches for files

<From IsRegex="true">c:\\some\\folder.*\\notepad\+\+.config </From>
<!-- Notice that there are no escaped characters here -->

Folder matching with recursion

The regular expression .* is used for recursive pattern matching, and can be used in redirections to redirect all the files, folders and subfolders from one location, to another.

<From IsRegex="true">c:\\some[.]*</From>

Will match the following


Folder matching without recursion

The regular expression [^\\]* is used for non-recursive pattern matching - it will NOT find a match for files or folders in sub folders because no soon as it encounters the path seperator '\' the matching stops.

<From IsRegex="true">c:\\[^\\]*\\adir</From>

Will match


Wont match


Common Errors

Special characters in the 'From' tag content must be escaped, in contrast with common redirection rules. The following characters have a special meaning in regular expressions so they must be escaped if the intention is to use them as literal strings, instead of as part of the regular expression: 

[ \ ^ $ . | ? * + ( )


Always test the expression you're building to ensure that it has the desired matching behaviour. There are a number of online regular expression engines which can be used for this, for example Regexr.

Was this article helpful?

Table of Contents

    Can't find what you're looking for?

    Contact Support