Supported Platforms
Related Documentation
- ACX, EX, J, M, MX, PTX, T Series
- Using Global Replace in a Junos Configuration
- Example: Using Global Replace in a Junos Configuration—Using the \n Back Reference
Common Regular Expressions to Use with the replace Command
Table 1: Common Regular Expressions to Use with the replace Command
Operator | Function |
---|---|
| | 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). |
\n | Back reference. Matches the numbered variable. This is only used with wildcard (.*), where the wildcard (.*) performs the matching, and the \n extracts the content from the variable and inserts it in the matched pattern. |
& | Back reference. Matches the entire match. |
Table 2 lists some replacement examples.
Table 2: Replacement Examples
Command | Result |
---|---|
replace pattern myrouter with router1 | Match: myrouter Result: router1 |
replace pattern " 192\.168\.(.*)/24" with " 10.2.\1/28" | Match: 192.168.3.4/24 Result: 10.2.3.4/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 |
Related Documentation
- ACX, EX, J, M, MX, PTX, T Series
- Using Global Replace in a Junos Configuration
- Example: Using Global Replace in a Junos Configuration—Using the \n Back Reference
Published: 2013-06-26
Supported Platforms
Related Documentation
- ACX, EX, J, M, MX, PTX, T Series
- Using Global Replace in a Junos Configuration
- Example: Using Global Replace in a Junos Configuration—Using the \n Back Reference