Regex expressions – User reference

A RegEx expression, or Regular Expression, is a set of characters that make up a search pattern, mainly used for the search of char subchains. Applied to the contents of an object’s file and folder structure, it allows for selecting the files or folders of the object to which to apply a specific action.

RegEx expressions are a standard in the computer world, although there are several variations depending on the field of application. RegEx expressions used in LIBSAFE follow the behavior defined for these expressions in .NET development and production environments. You can find a full reference for them in the MSDN pages https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx, as well as in a large number of web pages.

It is of high importance, or even of critical importance, to pay an extraordinary attention when writing RegEx expressions, as they are strictly applied by the system, and their way of building differs greatly from the use of any other common tool, for an average application user. For those users not fully understanding the use of these expressions, it is recommended that they copy the value for selecting all elements in places where the expressions are needed; this value is available in the accompanying help text in the interface.

Some common errors when writing a RegEx expression: forgetting that patterns are case sensitive by default, misunderstanding that character sequences are not the same as character sets, inserting blank spaces in expressions without realizing that the space becomes part of the chain pattern, ...

It is also important to understand that the general use of RegEx expressions goes far beyond the use that is made of them in the application. Elements such as grouping and self-references are not used by LIBSAFE.

To make it easy to insert expressions, you can find a set of examples hereafter. Beware, that in some occasions there may be more than one pattern to achieve the same result.

Function. Description.

RegEx expression

Select all elements.

This expression will select all objects / folders / files, where applied. It is the one to be used by default, if in doubt of what expression to use.

.*

Select all elements containing a TeXt, case sensitive.

TeXt

Select all elements containing a TEXT, case insensitive.

(?i)text

(?i)TEXT

Select all elements beginning with text, case insensitive.

^(?i)text

Select all elements ending with text, case insensitive.

(?i)text$

Select all elements with an exAct_teXt.

^exAct_teXt$

Select all elements containing the text jpg, ico or tiff, case insensitive. This is a typical example for selecting several folders in one only pattern; as when using the numerical sequence check. It would select folders such as jpg_image, THUMBNAILS_ICO, Tiff or Iconographic (beware that the chain has the subchain ico). See that the use of separation bars | is done with no added spaces.

(?i)(ico|jpg|tiff)

Select all elements that are exactly one of the texts jpg, ico or tiff, case insensitive. See that the use of separation bars | is done with no added spaces.

^(?i)(ico|jpg|tiff)$

Select chains that contain a 4-digit number.

The quantity of desired digits is to be changed at will.

\d{4}

Select chains containing between 3 and 8 digits.

The limits for the number of digits may be changed at will.

\d{3,8}

Select a subchain starting with a text, followed by a 4-digit number, and separated by a _. Case insensitive.

^(?i)text_\d{4}$

From the previous examples, the following operators should be highlighted:

  • ^ -> to indicate the start of the chain.

  • $ -> to indicate the end of the chain.

  • (?i) -> to set case insensitive checking.

Last updated