Regular Expressions

<< Click to Display Table of Contents >>

PackBench > 7.3 u1 > User Guide > Reference and Cheat Sheets 

Regular Expressions

Regular expressions (abbreviated to RegExp) are sequences of characters forming a search pattern that can be used to identify a textual material of a given pattern. The syntax of regular expression is standardized and used along many different products and operating systems, particularly for finding and replacing of functionalities.

 

PackBench uses regular expressions to provide a flexible way of defining compact text conditions, which can be further customized to exclude and include particular resources based on complicated rules and logic.

 

The following cheat sheet presents some commonly used regular expression patterns and example patterns with explanations.

 

Phrase

Description

Examples

Letters or digits

Literal meaning, case sensitive

Abc matching Abc but not abc

Pipe (|)

Alternative

A|b matching A, b, Ab but not BC

Asterisk (*)

Zero or more instances of the previous set

A*b matching Aaaaab, Ab, bcd but not Ac

A|b* matching a, b, bb, bbb but not CDE

Plus (+)

One or more instances of the previous set

A+b matching Ab, AAAb but not b

(a|b)+cd matching acd, bcd, aaacd, abcd, bacd but not cd

Folder[0-9]+ matching Folder1, Folder2, Folder21 but not Folder or FolderA

Question mark (?)

Zero or one instance of the previous set

Ab?(c|d) matching Ac, Ade, Abcd but not Abb

Round brackets ( and )

Grouping of sets

(abc|def)ghi matching abcghi, defghi, abcdefghi but not abcdef

(a|b|c)?def matching adef, cdefghi, def but not abc

Caret (^)

On the beginning of the string marks that no characters are allowed before

^abc matching abc, abcdef but not defabc

^(folder1|folder2|folder3)\\test matching folder1\test, folder2\test\test2 but not C:\folder1\test

Dollar ($)

At the end of the string marks that no characters are allowed after

:\\test\\folder$ matching C:\test\folder, D:\test\folder but not C:\test\folder1

Square brackets [ and ]

Allowed set of characters

[a-z] matching abc, def but not 123

^[A-D]:\\Test\\ matching C:\Test\ and D:\Test\ but not E:\Test\

folder[a-zA-Z0-9] matching folderA, folder1 but not folder\test

Caret in square brackets [^]

In square brackets – negation of character set

C:\\folder[^\\]*\\test will match C:\folder\test but not C:\folder\subfolder\test

Dot (.)

Any character

Folder.\\test will match FolderA\, Folder4\, Folder$\ but not Folder\

Backslash (\)

Escape character

C:\\test\\test2 matches C:\test\test2 but not C:\\test\\test2

Test\* matches Test*

Test\(a\) matches Test(a) but not Testa

(?i)

Used at the beginning on the expression – do not match case

(?i)abc will match abc, Abc, ABC123 but not 123

 

Examples

^(?i)[{(]?[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$

 

Matches

Does not match

{057B21232-ED42-11CE-BACD-00AA0CA7623}

(057B21232-ED42-11CE-BACD-00AA00CA7623)
057b21232ed4211cebacd00aa00ca7623

057B21232-ED42-11CE-BACD-00AA00CA7623

(123)
123-1412-1231
abc
aaa(057B21232-ED42-11CE-BACD-00AA00CA7623)

 

^(?i)(%windir%)\\Installer$

 

Matches

Does not match

%windir%\Installer

%windir%\INSTALLER

%windir%\Installer\123-123.msi

 

^(?i)%ProgramFiles\(x86\)%\\Common Files\\(InstallShield|Wise Installation)$

 

Matches

Does not match

%ProgramFiles(x86)%\Common Files
\InstallShield

%ProgramFiles(x86)%\COMMON FILES
\Wise Installation

%ProgramFiles(x86)%\Common Files\Microsoft

%ProgramFiles%\Common Files\InstallShield

%ProgramFiles(x86)%\Common Files\

%ProgramFiles(x86)%\Common Files\
Wise Installation\Subfolder

 

^unins(|t|tall)\d*\.(cif|cfg|dat|dll|ini|exe|xml|lnk)$

 

Matches

Does not match

uninst.exe

uninst_myApp.lnk

uninstallapp.cfg

uninst.ini

MyProgram_uninstall.cfg

uninstall.txt

unins.txt

 

^_isreg32\.dll$

 

Matches

Does not match

_isreg32.dll

_ISREG32.dll

isreg32.dll

_isreg.dll

_isreg32.dll.backup

 

^(?i)(HKEY_LOCAL_MACHINE|HKEY_CURRENT_USER)\\(Software\\Wow6432Node|Software)
\\InstallShield

 

Matches

Does not match

HKEY_LOCAL_MACHINE\Software\InstallShield

HKEY_LOCAL_MACHINE\Software\Wow6432Node
\InstallShield

HKEY_CURRENT_USER\SOFTWARE\Wow6432Node
\InstallShield

HKEY_CURRENT_USER\Software\INSTALLSHIELD

HKEY_CLASSES_ROOT\Software\InstallShield 

HKEY_CURRENT_USER\Software
\Progrems\InstallShield

 

^%USERPROFILE%\\(.+\\)?Temp$

 

Matches

Does not match

%USERPROFILE%\Temp

%USERPROFILE%\test\Temp

%USERPROFILE%\test\test2\Temp

%USERPROFILE%\Temp2

“%USERPROFILE%\Temp”

%userprofile%\Temp