Technical Documentation

Common Regular Expressions to Use with the replace Command

Table 1: Common Regular Expressions to Use with the replace Command




Indicates that a match can be one of the two terms on either side of the pipe.


Used at the beginning of an expression, denotes where a match should begin.


Used at the end of an expression, denotes that a term must be matched exactly up to the point of the $ character.

[ ]

Specifies a range of letters or digits to match. To separate the start and end of a range, use a hyphen ( - ).

( )

Specifies a group of terms to match. Stored as numbered variables. Use for back references as \1 \2 .... \9.


0 or more terms.


One or more terms.


Any character except for a space (" ").


A backslash escapes special characters to suppress their special meaning. For example, \. matches . (period symbol).


Back reference. Matches the nth group.


Back reference. Matches the entire match.

Table 2 lists some replacement examples:

Table 2: Replacement Examples



replace pattern myrouter with router1

Match: myrouter

Result: router1

replace pattern " 192\.168\.(.*)/24" with " 10.2.\1/28"



replace pattern " 1.\1" with " abc&def"

Match: 1.1

Result: abc1.1def

replace pattern 1.1 with " abc\&def"

Match: 1#1

Result: abc&def

Published: 2010-01-17