R12.1-JA-2025June05

Single-line Rule

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 components:

Information Note: Line Pattern does not apply to Table Parser.

This section introduces the following five types of line patterns in the system, each with its syntax.

Simple Line Pattern

A 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
StringVersion 12.2(53)SE2, RELEASE SOFTWAREVersion $version, RELEASE SOFTWARE
Multi-stringR1 uptime is 51 weeks, 4 days, 23 hours, 3 minutesuptime is $mstring:uptime
IntegerMTU 1500 bytesMTU $int:mtu bytes
Float/DoubleNext hello sent in 1.824 secsNext hello sent in $float:hello_time secs
Booleansingle-connect=falsesingle-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)
Dummy0 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.

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$

Information 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) being 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 Variable 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 of the paragraph.
Format
Sample of Raw Text
Sample of Definition
LinesByVariable[$var]: $var1, $var2Graphical user interface, text, application, email

Description automatically generatedGraphical user interface, text, application, email

Description automatically generated
For more information, see Parse the Line of VariableParse the Line Between Variable.

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 patterns, including ^ and $.
Format
Sample of Raw Text
Sample of Definition
LinesByKeyword[$var]: simple line patternGraphical user interface, text, application

Description automatically generated

For more information, see Parse the Lines of Keyword.

Match Lines by Regex

The system provides a pattern of matching lines by regex (LinesByRegex) to parse multiple lines of raw CLI text for a specified regex. 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.
  • Support simple regex.
Format
Sample of Raw Text
Sample of Definition
LinesByRegex[$access]: simple regex

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 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, $var2Graphical user interface, text, application

Description automatically generated

Information Note: The pattern of matching value by variables (SelectVariable) can only be used in the variable line pattern of Variable Parser or Paragraph Parser.

Regex

The system provides a specific regex pattern using the 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.

PatternDescriptionFormatSample of Raw TextSample of Regex
Regex for a Single LineA 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 LinesA regular expression to parse strings crossing lines.mregex[$var1]:regex expressionMulticast 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".
\dMatch any decimal digit from 0 to 9.
\sMatch any whitespace character, equivalent to the set [\f\n\r\t\v].
\SMatch any non-whitespace character, equivalent to the set [^ \f\n\r\t\v].

Use '#NOT' in Line Pattern

The operator #NOT can be used in visual parser to enhance the parsing ability. #NOT in a line pattern means negation, and has the following two formats:

  • # NOT: For example, #NOT( permit| deny) will match lines that do not include permit or deny.
  • ^#NOT: For example, ^#NOT( permit| deny) will match lines that do not start with permit or deny.

Example of using ‘#NOT’:

Parse acl_config for every acl_id, use ^#NOT to get correct end of paragraph.

  1. Parse variable $ip_acl_id, use (standard|extended) in the line pattern to narrow down the correct ip access-list xx content.
  2. Parse variable $ip_acl_config, define parse lines: Parse Lines > The line between $ip_acl_id to End.
  3. Add End of Paragraph and fill the line pattern with ^#NOT( permit| deny) to fine the correct paragraph.
    Information Tip: It is required to add space before permit and deny in this example.