Show/Hide Toolbars

EmEditor Help

Navigation: EmEditor Help > How to... > Search

EmEditor How to: Replacement Expression Syntax

Scroll Prev Top Next More
EmEditor Home - EmEditor Help - How to - Search

Replacement Expression Syntax

Replacement expressions can be used when using regular expression or number range to replace.

The following expressions are available for the Replace With box in the Replace dialog box and in the Replace in Files dialog box.

\0

Indicates a back reference to the entire regular expression.

\1 - \9

Indicates a back reference - a back reference is a reference to a previous sub-expression that has already been matched. The reference is to what the sub-expression matched, not to the expression itself. A back reference consists of the escape character "\" followed by a digit "1" to "9", "\1" refers to the first sub-expression, "\2" to the second etc.

$10, $11, $12, ...

Indicates a back reference more than 9. Equivalent to \k<10>, \k<11>, \k<12>, ....

\k<name>

Indicates a named back reference. A named back reference is a reference to a previously matched named capturing group using this form: (?<name>expression). If "name" is a number, it indicates a numbered back reference, equivalent to \1, \2, \3, ...

\n

A newline character.

\r

A carriage return in case of Replace in Files. See also To Specify newline characters.

\t

A tab.

\L

Forces all subsequent substituted characters to be in lowercase.

\U

Forces all subsequent substituted characters to be in uppercase.

\H

Forces all subsequent substituted characters to be in half-width characters.

\F

Forces all subsequent substituted characters to be in full-width characters.

\E

Turns off previous \L, \U, \F, or \H.

\J

Specifies that JavaScript is used as the expression. \J must be placed at the beginning of the replacement expression. Can be combined with back references. The cell function can also be used in the script. For instance,

Replacement Expression

Meaning

\J "\0" + "abc"

joins the matched string and "abc"

\J "\0".substr( 0, 5 );

returns the first 5 characters of the matched string

\J \0 * 100;

multiply a matched number with 100

\J parseFloat( \0 ).toFixed(2);

rounds a matched number to 2 decimal places

\J cell( -1 )

returns the text in the left neighbor cell, relative to the matched cell.

\J parseFloat( cell( -1 ) ) + parseFloat( cell( -2 ) )

returns the sum of the two neighboring cells on the left

(?Ntrue_expression:false_expression)

If sub-expression N was matched, then true_expression is evaluated and sent to output, otherwise false_expression is evaluated and sent to output. For example, (?1foo:bar) will replace each match found with foo if the sub-expression \1 was matched, and with bar otherwise. Alternatively, you can write the expression in this form: (?{1}foo:bar)

$(Path)

File path.

$(Dir)

File directory.

$(Filename)

File name without extension.

$(FilenameEx)

File name with extension.

$(Ext)

File extension.

$(Lines)

Number of lines (cannot be used in Replace in Files).

$(CsvColumns)

Number of CSV columns (cannot be used in Replace in Files).

cell function (beta)

The cell function can be used in JavaScript if \J is also specified. This function retrieves the text in the specified CSV cell.

[JavaScript]

str = cell( iColumn [, yLine [, flags ] ] );

Parameters

iColumn

Specifies the index of the column of the text you want to retrieve, expressed in the relative position from the current position unless 8 is specified in flags.

yLine

Specifies the line number of the text to retrieve, expressed in the relative position from the current position unless 8 is specified in flags. If omitted, 0 is specified.

flags

Specifies a combination of the following values. 0, 1, and 2 cannot be used together. If omitted, 1 is specified.

0

The returned text may not include surrounded double-quotes or delimiters.

1

The returned text may include surrounded double-quotes but no delimiters.

2

The returned text may include surrounded double-quotes and delimiters.

8

iColumn and yLine parameters are expressed in 1-based absolute values.

Notes

Many new methods in modern JavaScript/ECMAScript are not available in EmEditor. The Replace Expressions use Chakra (equivalent to Microsoft Edge Legacy), and support up to ECMAScript 5.1, thus newer methods introduced after ECMAScript 5.1 are not supported.

See Also

Regular Expression Syntax

Copyright © 2003-2021 by Emurasoft, Inc.