Text Workbench Online Help Submit feedback on this topic   

Regular Expressions

This topic contains information on regular expression control switches and operators, as well as important notes on using regular expressions.

IMPORTANT!
Non-alphanumeric symbols in search expressions must be escaped with a backslash. For example, if you need to find a symbol # using regular expressions, you must type \#. Otherwise, symbols are treated as regular expression operators.

Note:
Literal switches are case-sensitive! For example, \s matches whitespace, while \S matches non-whitespace.

Repeat qualifiers (@,#,*,+) can be applied (for examlpe: .+) to match text segments as large as 2 Mb or less.

Note:
Greedy means matching this condition as much as possible, disregarding further coinciding or alike conditions. See more detailed description of the greedy and non-greedy modes in topic Using Regular Expressions.

Expressions for searching

ExpressionDescription.
^ Match the beginning of file.

HandyFile Find And Replace searches the file as if it is a single line. This allows to search for the line-breaking characters and text blocks, manipulate and replace them without any hassle.

To insert any text in the beginning of a file, type:
 ^. in the Find What field and
 \0text_to_insert in the Replace With field.
$Match the end of file.
.Match any character.
[ ]Match characters in set.
Specify set (e.g. [aghet2]) or range (e.g. [A-Z]).
[^ ]Match characters not in set (e.g. [^A-Z]).
?Match previous pattern 0 or 1 times (greedy).
|Match previous or next pattern.
@Match previous pattern 0 or more times (non-greedy).
#Match previous pattern 1 or more times (non-greedy).
*Match previous pattern 0 or more times (greedy).
+Match previous pattern 1 or more times (greedy).
{ }Group characters to form one pattern.
( )Group and remember for further referencing and use.
\Quote next character
(only of not a-z; e.g. "\>" designates symbol ">").
<Match beginning of a word.
>Match end of a word.
\tMatch 0x09 (tab).
\eMatch escape (^E).
\sMatch whitespace (tab, space, CR, LF). More...
\SMatch non-whitespace.
\wMatch word character.
\WMatch non-word character.
\dMatch digit character.
\DMatch non-digit character.
\UMatch uppercase.
\LMatch lowercase.
\CMatch case sensitively from here on.
\cMatch ignoring the case from here on.
\xNNCharacter with hexadecimal value of NN, where N=[0-9A-F].
\dNNNCharacter with decimal value of NNN, where N=[0-9].
\oNNCharacter with octal value of NNN, where N=[0-7].

Expressions for replacing

ExpressionDescription.
\0Place whole found text.
\#Place contents of the stored group numbered by the "#"
[groups are defined by braces (...) in the search expression]; #=[1-9].
\tPlace tab character.
\uMake next character uppercase.
\lMake next character lowercase.
\UForce further output uppercase.
\LForce further output lowercase.
\ETurn off case transformation (after the use of \U or \L)
\fInsert current file name and extension (file.ext).
\FInsert current file name only, without extension (file).
\XInsert current file extension (.ext). More...
\RInsert a random 8-digit number. For example: 267124D2.
\SInsert a random 8-digit number that remains constant within a single replace expression.

For example, the expression
id="\S" onClick="openPageId('\S')"
might insert
id="267124D2" onClick="openPageId('267124D2')"
\ZheConverts the next symbol to numeric HTML entity.
\ZhETurns on the ASCII - to - HTML Entity conversion. Makes all further output converted to numeric HTML entities. For example, the operator 
\ZhEMyString
will insert
&#77;&#121;&#83;&#116;&#114;&#105;&#110;&#103;
\ZhxTurns off the ASCII - to - HTML Entity conversion previously initialised by \ZhE.
\Zi:"file_path_name"Inserts contents of the specified file. file_path_name must be a fully qualified absolute path name. For example, the command \Zi:"c:\MyWeb\style.css" will insert contents of the file c:\MyWeb\style.css.
\P[h]:"file_path_name"Executes the path name resolver.

Very often your files (for example, HTML pages) are stored in different folders and use reference to one file in some other folder (for example, CSS file). This operator allows to insert a path name of the referenced file relative to a processed file, given a fully-qualified path and name of the referenced file.

\P operator uses backslash as the path part separator. \Ph operator (h stands for HTML mode) uses forward slash.

If the given path name cannot be converted to a relative path, the provided path name is inserted.

See Remarks for example.
\Pc[h]:"directory_path"Similar to operator \P. Executes the path name resolver on the currently processed file. Inserts path to the current file relative to the provided directory.

For example, if the current file is c:\dir1\dir2\dir3\file.ext and the directory_path is c:\dir1\dir2 , the operator \Pc:"c:\dir1\dir2" will insert .\Dir3\file.ext

\Pc operator uses backslash as the path part separator. \Pch operator (h stands for HTML mode) uses forward slash.

If conversion fails, the current file path name is inserted.
\Pd[h]:"ref_dir_path" Executes the reverse path name resolver on the directory of the currently processed file. Inserts path to the provided directory relative to the directory of the current file.

For example, if the current file directory is c:\dir1\dir2\dir3 and the ref_dir_path is c:\dir1 , the operator \Pd:"c:\dir1" will insert ..\..

\Pd operator uses backslash as the path part separator. \Pdh operator (h stands for HTML mode) uses forward slash.

If conversion fails, the current file path is inserted. In all cases, no trailing slash is appended.
\xNNInsert character with hexadecimal value of NN, where N=[0-9A-F].
\dNNNInsert character with decimal value of NNN, where N=[0-9].
\oNNInsert character with octal value of NNN, where N=[0-7].

Remarks

Example of using the path name resolve operator

For example, you are processing files and folders in C:\MyWeb\HTML\Catalog. You want to insert a reference to a CSS file style.css stored in the folder C:\MyWeb\HTML. You could write the following replace expression:

<LINK REL=stylesheet href=\"\ph:"c:\\myweb\\html\\style.css"\" TYPE="text/css">

This will insert the following text in HTML files in C:\MyWeb\HTML\Catalog:

<LINK REL=stylesheet href="../style.css" TYPE="text/css">

and the following text in HTML files in C:\MyWeb\HTML\Catalog\dir1\dir2:

<LINK REL=stylesheet href=&style.css" TYPE="text/css">

Note!
Root parts of path names of both a referenced and processed file must be the same. It means that they must have a common drive letter.