Single-line rule (line pattern) represents a type of expression serving to parse variables that reside in one or multiple lines of text. The system adopts line-pattern-matching syntax to apply the given line patterns to identify and parse variables.

You can write a line pattern in the following types of parser and parser components:

Simple Variables Parser (Variable Line)

Paragraph Parser (Variable Line, Identifier (ID) Line and Parent Line)

Start/End Line

Note: Line Pattern is not applicable to Table Parser and Text Parser.

This section introduces the following five types of line patterns in the system, and each one has its own syntax.

Simple Line Pattern

Simple line pattern is the most widely used line pattern to parse variables in one line.

The following table introduces sample pairs of raw text and simple line patterns for each variable type.

Variable Type

Sample of Raw Text

Sample of Line Pattern

String

Version 12.2(53)SE2, RELEASE SOFTWARE

Version $version, RELEASE SOFTWARE

Multi-string

R1 uptime is 51 weeks, 4 days, 23 hours, 3 minutes

uptime is $mstring:uptime

Integer

MTU 1500 bytes

MTU $int:mtu bytes

Float/Double

Next hello sent in 1.824 secs

Next hello sent in $float:hello_time secs

Boolean

single-connect=false

single-connect=$bool:single_conn

Enumeration

Auto-duplex, Auto-speed

Full-duplex, 100Mb/s, 100BaseTX/FX

Haft-duplex, 100Mb/s, 100BaseTX/FX

$duplex(Full-duplex|Half-duplex|Auto-duplex)

Dummy

0 input errors, 0 CRC, 0 frame, 0 overrun

$int:_dummy input errors, $int:crc CRC, $int:_dummy frame, $int:overrun overrun

The following two characters can be used in a simple line pattern to match the start/end of a string or a line. See Using Special Characters for more details.

Character

Description

Sample Line Pattern

^

Match the start of a line.

^$intf is $mstring:state, line protocol is $status

$

Match the end of a line.

Neighbor priority is $priority, State is $state, $int:changes state changes$

Note: When a variable defined in a simple line pattern does not include a specific data type, e.g., $var1, its variable type will be auto-assigned depending on the data type of its parsed values. The system provides this auto-validation mechanism to avoid a numerical value (integer/float/double-type) is mistakenly defined and parsed as a string, which cannot be compared or processed as numbers in further Network Intent Automation.
-If the variable value parsed by a keyword parser is a numeric one (integer or float), then its variable type will be recognized as integer or float.
-For a paragraph parser, if all the parsed values of a variable are always numeric (integer or float), then its variable type will be recognized as integer or float. If the values contain both integer and float, then it will be recognized as a float.

Match Lines by Variable

The system provides a pattern of matching lines by variable (LineByVariable) and parses multiple lines of raw CLI text for specified variables. It follows the following detailed rules:

Using a comma (,) to separate var1 and var2 only returns the lines where the variables reside.

Using a hyphen (-) to connect var1 and var2 returns the consecutive lines from the line of var1 to the line of var2. If the end line is not specified in the pattern, for example, “LinesByVariable[$var]:$var1-“, it will return the rest part of the paragraph.

Format

Sample of Raw Text

Sample of Definition

LinesByVariable[$var]: $var1, $var2

LinesByVariable[$var]: $var1-$var2

LinesByVariable[$var]: $var1-$var2, $var3

Note: The pattern of matching lines by variable (LinesByVariable) can only be used in the variable line pattern of keyword parser or paragraph parser.

Match Lines by Keyword

The system provides a pattern of matching lines by keyword (LinesByKeyword) to parse multiple lines of raw CLI text for a specified keyword. It follows the following detailed rules:

Return all matched lines between the start/end line of simple variable group or sub-paragraphs of paragraph group.

Allow simple line pattern, including ^ and $.

Format

Sample of Raw Text

Sample of Definition

LinesByKeyword[$var]: simple line pattern

Note: The pattern of matching lines by keyword (LinesByKeyword) can only be used in the variable line pattern of keyword parser or paragraph parser.

Select Variable

The system provides an option (SelectVariable) to parse the values of specified variables in order of appearance. It follows the following detailed rules:

Use a comma (,) to separate two variables, the value of which will be used as the parsed result depends on the display order and its availability. For example, if the value of the first variable is not null, it will be used as the parsed result; otherwise, the value of the second variable will be parsed, and so on.

Only the variables that have been defined in the previous line patterns can be used in this pattern. The variables defined in the pattern of matching lines by keyword (LinesByKeyword) and matching lines by variable (LinesByVariable) are allowed.

Format

Sample of Raw Text

Sample of Definition

SelectVariable[$var]: $var1, $var2

Note: The pattern of matching value by variables (SelectVariable) can only be used in the variable line pattern of keyword parser or paragraph parser.

Regex

The system provides a specific regex pattern by using regular expression (regex for short). Starting with a specific keyword: regex or mregex, the regex pattern declares all the required variables (separated by a comma) in a pair of square brackets, followed by a colon (:) and regex that can parse text lines. Each pair of parentheses in a regex represents a capturing group to group listed characters to form a sub-pattern, and their matched values will be assigned to each variable defined inside the pair of square brackets by sequence.

You can use the following two types of regex patterns to define a visual parser.

Pattern

Description

Format

Sample of Raw Text

Sample of Regex

Regex for a Single Line

A regular expression to parse strings in one line.

regex[$type1:var1, $type2:var2]:regex expression

3.255.255.12   em2.0   2.2.2.2:0   12

192.168.1.1     em1.0   2.2.2.2:0   12

172.16.8.12     em3.0   2.2.2.2:0   12

regex[$nbr_addr,$intf,$label_space_id,$int:hold_time]:^(\d+\.\d+\.\d+\.\d+)\s+(\S+)\s+(\S+)\s+(\d+)

Regex for Multiple Lines

A regular expression to parse strings crossing lines.

mregex[$var1]:regex expression

Multicast reserved groups joined: 224.0.0.1    224.0.0.2    224.0.0.13   224.0.0.22
Directed broadcast forwarding is disabled

mregex[$multicast]:Multicast reserved groups joined: (.*?)Directed

Frequently Used Regex Syntax

The following table introduces the most popular regex syntax in detail.

Character

Description

.

Match any character except a new line.

\

Escape a special character.

()

Group all listed characters to form a sub-pattern.

^

Match the start of a string, or the start of a line in Multiline mode.

$

Match the end of a string or the end of a line in Multiline mode.

*

Match the preceding shortest pattern zero-or-more times. For example, "ab*" can match "a", "ab", and "abb".

+

Match the preceding shortest pattern once or more times. For example, "be+" can match "been" and "bent".

?

Make the preceding shortest pattern optional. It matches zero or one time. For example, "ab?" can match "a" and "ab".

\d

Match any decimal digit from 0 to 9.

\s

Match any whitespace character, equivalent to the set [\f\n\r\t\v].

\S

Match any non-whitespace character, equivalent to the set [^ \f\n\r\t\v].