Regular expressions are strings that define patterns to match character sequences. They can be used in Cisco IOS show commands and AS-Path access-lists to match BGP prefixes based on AS-Path information. Regular expression characters have specific meanings, such as ^ and $ to match the start and end, [] for ranges, and * + ? for quantity. An example expression matches routes originated from directly connected ASes or their customers by representing AS numbers as "X" and using quantity symbols to account for multi-digit ASNs.
This document discusses lists in Python. It defines lists as mutable sequences that can contain elements of different types. Lists can be nested within other lists. Common list operations include accessing elements by index, slicing lists, modifying lists by assigning to indices, and using list methods like append(), pop(), sort(), and len(). The document provides examples of creating, accessing, modifying, and traversing lists in Python code.
This document discusses inverse functions. It provides examples of functions and their inverses, including:
- A function f(x) = {(1, 4), (2, 6), (5, 3)} and its inverse f-1(x) = {(4, 1), (6, 2), (3, 5)}.
- Showing that composing a function with its inverse results in the identity function f-1(f(x)) = x and f(f-1(x)) = x.
- Finding the inverse of the function f(x) = 2/x and graphing a function and its inverse.
This document discusses inverse functions. It provides examples of functions and their inverses, including:
- A function f(x) = {(1, 4), (2, 6), (5, 3)} and its inverse f-1(x) = {(4, 1), (6, 2), (3, 5)}.
- Showing that composing a function with its inverse results in the identity function: f-1(f(x)) = x and f(f-1(x)) = x.
- Finding the inverse of the function f(x) = 2x^2 and graphing a function and its inverse.
This document provides instructions for configuring packet capture on a Cisco ASA firewall. It describes using the packet capture wizard in ASDM or CLI commands to define a capture named "capin" on the inside interface and "capout" on the outside interface. The capture filters use access lists to match traffic between the inside and outside networks. The show capture command can then be used to view the captured packets.
This document provides an overview and study guide for the CCIP MPLS exam. It discusses key MPLS concepts like label distribution, label switching, and MPLS VPNs. The exam tests knowledge of MPLS fundamentals, frame and cell mode MPLS, MPLS VPN implementation, complex MPLS VPNs, and internet access from an MPLS VPN. It provides details on topics covered in the exam and guidance on how to prepare.
This document provides an overview of Cisco Quality of Service (QoS) methods and configuration. It discusses legacy CLI, Modular QoS CLI (MQC), and AutoQoS features for implementing QoS policies. It also covers traffic classification, marking, queuing mechanisms like weighted fair queuing (WFQ) and low-latency queuing (LLQ), and configuration of QoS on switches.
This document discusses troubleshooting basic BGP connectivity between two sites. It describes the three tables that BGP connectivity is built upon: the neighbor table showing BGP session state, the BGP table learning prefixes, and the IP route table selecting best routes from the BGP table based on attributes like weight, local preference, AS-path length. The document also states that a candidate with BGP knowledge should be able to accurately describe connectivity between two sites using BGP.
This document discusses lists in Python. It defines lists as mutable sequences that can contain elements of different types. Lists can be nested within other lists. Common list operations include accessing elements by index, slicing lists, modifying lists by assigning to indices, and using list methods like append(), pop(), sort(), and len(). The document provides examples of creating, accessing, modifying, and traversing lists in Python code.
This document discusses inverse functions. It provides examples of functions and their inverses, including:
- A function f(x) = {(1, 4), (2, 6), (5, 3)} and its inverse f-1(x) = {(4, 1), (6, 2), (3, 5)}.
- Showing that composing a function with its inverse results in the identity function f-1(f(x)) = x and f(f-1(x)) = x.
- Finding the inverse of the function f(x) = 2/x and graphing a function and its inverse.
This document discusses inverse functions. It provides examples of functions and their inverses, including:
- A function f(x) = {(1, 4), (2, 6), (5, 3)} and its inverse f-1(x) = {(4, 1), (6, 2), (3, 5)}.
- Showing that composing a function with its inverse results in the identity function: f-1(f(x)) = x and f(f-1(x)) = x.
- Finding the inverse of the function f(x) = 2x^2 and graphing a function and its inverse.
This document provides instructions for configuring packet capture on a Cisco ASA firewall. It describes using the packet capture wizard in ASDM or CLI commands to define a capture named "capin" on the inside interface and "capout" on the outside interface. The capture filters use access lists to match traffic between the inside and outside networks. The show capture command can then be used to view the captured packets.
This document provides an overview and study guide for the CCIP MPLS exam. It discusses key MPLS concepts like label distribution, label switching, and MPLS VPNs. The exam tests knowledge of MPLS fundamentals, frame and cell mode MPLS, MPLS VPN implementation, complex MPLS VPNs, and internet access from an MPLS VPN. It provides details on topics covered in the exam and guidance on how to prepare.
This document provides an overview of Cisco Quality of Service (QoS) methods and configuration. It discusses legacy CLI, Modular QoS CLI (MQC), and AutoQoS features for implementing QoS policies. It also covers traffic classification, marking, queuing mechanisms like weighted fair queuing (WFQ) and low-latency queuing (LLQ), and configuration of QoS on switches.
This document discusses troubleshooting basic BGP connectivity between two sites. It describes the three tables that BGP connectivity is built upon: the neighbor table showing BGP session state, the BGP table learning prefixes, and the IP route table selecting best routes from the BGP table based on attributes like weight, local preference, AS-path length. The document also states that a candidate with BGP knowledge should be able to accurately describe connectivity between two sites using BGP.
This presentation shows slides to explain about the String functions in MySQL. It is suitable for students in IT studying DBMS, MySQL and Subject 065 Informatics Practice according to CBSE syllabus
This document provides examples and explanations of regular expressions. It covers basic regex syntax like | (or), [] (character sets), . (wildcards), ^/$ (start/end anchors), and *+? (quantifiers). Simple examples demonstrate matching numbers, ranges, and strings. More complex examples show grouping, repetition, and matching BGP autonomous system paths. The document concludes with examples of using regex to filter Cisco IOS show command output.
The document introduces various SQL techniques for limiting and filtering result sets using the WHERE clause, including compound criteria with AND and OR operators, comparisons, ranges, wildcards, escape characters, and pattern matching. Key topics covered include filtering rows by state, combining multiple filters, using operators like BETWEEN, LIKE with wildcards, and matching patterns within brackets.
The document introduces various SQL techniques for limiting and filtering result sets using the WHERE clause, including compound criteria with AND and OR, comparisons, ranges, wildcards, escape characters, and pattern matching. Key points covered include filtering rows by state, combining multiple filters, using operators like BETWEEN, LIKE with wildcards, and matching patterns within brackets.
This document provides an overview of regular expressions (RE) for PHP, including what they are, why they are useful, basic syntax, and examples of using RE to match, find, replace, and split text. RE allow complex text matching and are available in most programming languages including PHP. They can be used to validate formats, extract data, and make replacements in text.
The document discusses string manipulation and regular expressions. It provides explanations of regular expression syntax including brackets, quantifiers, predefined character ranges, and flags. It also summarizes PHP functions for regular expressions like ereg(), eregi(), ereg_replace(), split(), and sql_regcase(). Practical examples of using these functions are shown.
Perl is an open-source, cross-platform scripting language that is multi-paradigm and uses dynamic typing. It was created in 1987 and is popular for web programming using CGI scripts. Perl has scalars, arrays, hashes, and complex data types like references that allow it to represent complex data structures. It supports common programming constructs like conditionals, loops, subroutines, pattern matching and more.
This document provides an overview of strings in PHP. It discusses single and double quote strings and how they differ in handling escape sequences and variable interpolation. It also covers the heredoc syntax. The document explains functions for comparing, manipulating, and extracting substrings from strings. These include strcmp(), strlen(), substr(), and regular expression functions. It provides examples of escaping characters, accessing strings as arrays, and using strings with functions like number_format(). Overall, the document is a guide to the basics of strings and common string functions in PHP.
String in programming language in c or c++Azeemaj101
This document discusses strings in C++. It defines a string as a sequence of characters and provides examples. It explains that strings can be represented using C-style character arrays or the C++ string class. When using character arrays, strings are null-terminated and common functions like strcpy(), strcat(), and strlen() are used. The C++ string class provides a safer alternative with useful methods like assign(), append(), insert(), replace(), erase(), find(), and more. It also supports all C++ operators and returns the string length.
Regular expressions provide a concise and flexible means of matching patterns in text strings. They use a formal language with special characters that match particular characters, words, or character patterns. Regular expressions can be used to search for text that matches a pattern, or to extract portions of a string that match the pattern. Common operations include searching, extracting email addresses from strings, and parsing strings into components.
The document summarizes key concepts about strings and regular expressions in Java. It discusses that strings are immutable sequences of characters represented by the String class, and how to manipulate strings. It also covers that regular expressions provide a concise way to match patterns in strings using special characters. Finally, it notes that the StringBuffer and StringBuilder classes allow mutable string operations by modifying objects instead of creating new String objects.
Folio3 is a development partner that focuses on designing custom enterprise, mobile, and social media applications. It was founded in 2005 and has over 200 employees across offices in the US, Canada, Bulgaria, and Pakistan. Folio3 provides services for areas like enterprise solutions, mobile apps, and websites. Some of its clients include companies in healthcare, digital media, and supply chain industries. The document then provides an overview of regular expressions including literal characters, special characters, character classes, grouping, backreferences, and lookarounds.
This document discusses server-side form validation in PHP. It covers checking for empty fields, field lengths, value ranges, and formats using regular expressions. Specific PHP functions discussed include preg_match() for pattern matching, preg_replace() for search and replace, and ereg() as an alternative to preg_match() for POSIX regular expressions. Examples are provided to validate dates, names, numbers, lengths, and ranges to restrict user-submitted form data to required standards before processing.
The SELECT statement is used to retrieve data from one or more tables. It allows you to select specific columns, rows, and expressions. The general syntax includes keywords like SELECT, FROM, WHERE, and clauses for filtering, sorting, grouping, and joining results. Examples demonstrate how to select all data, particular rows and columns, use aliases, DISTINCT, comparison operators, patterns, ranges, and handle NULL values.
Ciarán Walsh's PHPNW08 slides:
In the right hands regular expressions can be a powerful tool, but it’s also far too easy for them to be used badly, or in the wrong situations.
This talk will kick off with a look at alternatives to regular expressions, for when the power of pattern matching is not required, and will also go over some cases when there are better alternatives available.
Then there will be a brief refresher on pattern syntax and some general tips and tricks to help when constructing regular expressions, before we go on to look at some situations where the use of pattern matching is a good fit, how to solve some common problems, and some common pitfalls when writing patterns.
The document discusses various methods for working with string objects in Python. It covers how to create, access, modify, compare and search strings. Some key string methods mentioned include len() to get the length, slicing to extract substrings, concatenation with +, checking for substrings with in/not in, comparing with relational operators, iterating with for loops, testing characters with isalpha() etc. and searching/replacing with endswith(), find(), replace() among others.
USE IMDB -- ensures correct database is active G.docxmadlynplamondon
This document contains the text of 10 questions for a SQL lab assignment on the IMDB database. For each question, students are instructed to insert their SQL query in the provided comment blocks to retrieve and display specific data based on the question parameters. The questions cover topics like filtering records, aggregating data, using common table expressions, joins, ranking functions and substituting null values.
OSPF Beyond Stump-the-Chump_Interview_Questions - Part 01 -Duane Bodle
This presentation is meant to help other network engineers to understand and put OSPF into the production networks correctly and with the least pain possible. Make no mistake, OSPF designed and deploy incorrectly can and is a bad experience.
SIP is a protocol that establishes, modifies, and terminates multimedia sessions like internet phone calls. It works between the session and application layers and can work with both IPv4 and IPv6. SIP provides functions for user location, availability, capabilities, session setup, and management. It is a flexible protocol that allows developers to build additional features.
This presentation shows slides to explain about the String functions in MySQL. It is suitable for students in IT studying DBMS, MySQL and Subject 065 Informatics Practice according to CBSE syllabus
This document provides examples and explanations of regular expressions. It covers basic regex syntax like | (or), [] (character sets), . (wildcards), ^/$ (start/end anchors), and *+? (quantifiers). Simple examples demonstrate matching numbers, ranges, and strings. More complex examples show grouping, repetition, and matching BGP autonomous system paths. The document concludes with examples of using regex to filter Cisco IOS show command output.
The document introduces various SQL techniques for limiting and filtering result sets using the WHERE clause, including compound criteria with AND and OR operators, comparisons, ranges, wildcards, escape characters, and pattern matching. Key topics covered include filtering rows by state, combining multiple filters, using operators like BETWEEN, LIKE with wildcards, and matching patterns within brackets.
The document introduces various SQL techniques for limiting and filtering result sets using the WHERE clause, including compound criteria with AND and OR, comparisons, ranges, wildcards, escape characters, and pattern matching. Key points covered include filtering rows by state, combining multiple filters, using operators like BETWEEN, LIKE with wildcards, and matching patterns within brackets.
This document provides an overview of regular expressions (RE) for PHP, including what they are, why they are useful, basic syntax, and examples of using RE to match, find, replace, and split text. RE allow complex text matching and are available in most programming languages including PHP. They can be used to validate formats, extract data, and make replacements in text.
The document discusses string manipulation and regular expressions. It provides explanations of regular expression syntax including brackets, quantifiers, predefined character ranges, and flags. It also summarizes PHP functions for regular expressions like ereg(), eregi(), ereg_replace(), split(), and sql_regcase(). Practical examples of using these functions are shown.
Perl is an open-source, cross-platform scripting language that is multi-paradigm and uses dynamic typing. It was created in 1987 and is popular for web programming using CGI scripts. Perl has scalars, arrays, hashes, and complex data types like references that allow it to represent complex data structures. It supports common programming constructs like conditionals, loops, subroutines, pattern matching and more.
This document provides an overview of strings in PHP. It discusses single and double quote strings and how they differ in handling escape sequences and variable interpolation. It also covers the heredoc syntax. The document explains functions for comparing, manipulating, and extracting substrings from strings. These include strcmp(), strlen(), substr(), and regular expression functions. It provides examples of escaping characters, accessing strings as arrays, and using strings with functions like number_format(). Overall, the document is a guide to the basics of strings and common string functions in PHP.
String in programming language in c or c++Azeemaj101
This document discusses strings in C++. It defines a string as a sequence of characters and provides examples. It explains that strings can be represented using C-style character arrays or the C++ string class. When using character arrays, strings are null-terminated and common functions like strcpy(), strcat(), and strlen() are used. The C++ string class provides a safer alternative with useful methods like assign(), append(), insert(), replace(), erase(), find(), and more. It also supports all C++ operators and returns the string length.
Regular expressions provide a concise and flexible means of matching patterns in text strings. They use a formal language with special characters that match particular characters, words, or character patterns. Regular expressions can be used to search for text that matches a pattern, or to extract portions of a string that match the pattern. Common operations include searching, extracting email addresses from strings, and parsing strings into components.
The document summarizes key concepts about strings and regular expressions in Java. It discusses that strings are immutable sequences of characters represented by the String class, and how to manipulate strings. It also covers that regular expressions provide a concise way to match patterns in strings using special characters. Finally, it notes that the StringBuffer and StringBuilder classes allow mutable string operations by modifying objects instead of creating new String objects.
Folio3 is a development partner that focuses on designing custom enterprise, mobile, and social media applications. It was founded in 2005 and has over 200 employees across offices in the US, Canada, Bulgaria, and Pakistan. Folio3 provides services for areas like enterprise solutions, mobile apps, and websites. Some of its clients include companies in healthcare, digital media, and supply chain industries. The document then provides an overview of regular expressions including literal characters, special characters, character classes, grouping, backreferences, and lookarounds.
This document discusses server-side form validation in PHP. It covers checking for empty fields, field lengths, value ranges, and formats using regular expressions. Specific PHP functions discussed include preg_match() for pattern matching, preg_replace() for search and replace, and ereg() as an alternative to preg_match() for POSIX regular expressions. Examples are provided to validate dates, names, numbers, lengths, and ranges to restrict user-submitted form data to required standards before processing.
The SELECT statement is used to retrieve data from one or more tables. It allows you to select specific columns, rows, and expressions. The general syntax includes keywords like SELECT, FROM, WHERE, and clauses for filtering, sorting, grouping, and joining results. Examples demonstrate how to select all data, particular rows and columns, use aliases, DISTINCT, comparison operators, patterns, ranges, and handle NULL values.
Ciarán Walsh's PHPNW08 slides:
In the right hands regular expressions can be a powerful tool, but it’s also far too easy for them to be used badly, or in the wrong situations.
This talk will kick off with a look at alternatives to regular expressions, for when the power of pattern matching is not required, and will also go over some cases when there are better alternatives available.
Then there will be a brief refresher on pattern syntax and some general tips and tricks to help when constructing regular expressions, before we go on to look at some situations where the use of pattern matching is a good fit, how to solve some common problems, and some common pitfalls when writing patterns.
The document discusses various methods for working with string objects in Python. It covers how to create, access, modify, compare and search strings. Some key string methods mentioned include len() to get the length, slicing to extract substrings, concatenation with +, checking for substrings with in/not in, comparing with relational operators, iterating with for loops, testing characters with isalpha() etc. and searching/replacing with endswith(), find(), replace() among others.
USE IMDB -- ensures correct database is active G.docxmadlynplamondon
This document contains the text of 10 questions for a SQL lab assignment on the IMDB database. For each question, students are instructed to insert their SQL query in the provided comment blocks to retrieve and display specific data based on the question parameters. The questions cover topics like filtering records, aggregating data, using common table expressions, joins, ranking functions and substituting null values.
OSPF Beyond Stump-the-Chump_Interview_Questions - Part 01 -Duane Bodle
This presentation is meant to help other network engineers to understand and put OSPF into the production networks correctly and with the least pain possible. Make no mistake, OSPF designed and deploy incorrectly can and is a bad experience.
SIP is a protocol that establishes, modifies, and terminates multimedia sessions like internet phone calls. It works between the session and application layers and can work with both IPv4 and IPv6. SIP provides functions for user location, availability, capabilities, session setup, and management. It is a flexible protocol that allows developers to build additional features.
Project Business Case and Capital Justification for Implementation of Applica...Duane Bodle
Business Case and Capital Justification Presentation For
Application Performance Monitoring and Retrospective Network Analysis Implementation. *** This Presentation Has Been Sanitized of IP Information ***
This document discusses the different LSA (Link State Advertisement) types in OSPF (Open Shortest Path First) networking. It explains that LSA types 1 and 2 are intra-area and do not leave the area, while type 3 are inter-area and describe routes outside the area. LSA types 5 and 7 describe redistributed routes from other protocols into an OSPF area, with type 5 generated by ASBR (Autonomous System Boundary Router) and type 7 by ASBR within a NSSA (Not-So-Stubby Area).
BGP is an exterior gateway protocol used for routing between autonomous systems (AS) and is the main protocol for routing between Internet service providers. It uses TCP port 179 and establishes peering sessions between routers in different AS to exchange routing information. BGP selects the best path to a destination based on attributes like AS path length, local preference, and MED. It is used in situations like multi-homed customer networks and large enterprise networks connected to multiple ISPs or AS.
The document provides an overview of BGP (Border Gateway Protocol) including its uses, basics, route selection criteria, advertising networks, summarization, aggregation, securing peers, multihoming, filtering, and other configuration topics. BGP is an exterior gateway protocol used for routing between autonomous systems and uses TCP port 179. Key attributes include NEXT_HOP, AS_PATH, and ORIGIN.
1. February 28, 2012 [MUST HAVE REGULAR EXPRESSION PATTERNS]
Regular expressions are strings of special characters that can be used to search and find character patterns. Within
the scope of BGP in Cisco IOS regular expressions can be used in show commands and AS-Path access-lists to
match BGP prefixes based on the information contained in their AS-Path.
In order to understand how to build regular expressions we first need to know what the character definitions
arefor the regex function of IOS. The below table illustrates the regex characters and their usage. This information is
contained in the Cisco IOS documentation under the Appendix of Cisco IOS Terminal Services Configuration Guide,
Release 12.2.
+------------------------------------------------------+
| CHAR | USAGE |
+------------------------------------------------------|
| ^ | Start of string |
|------|-----------------------------------------------|
| $ | End of string |
|------|-----------------------------------------------|
| [] | Range of characters |
|------|-----------------------------------------------|
| - | Used to specify range ( i.e. [0-9] ) |
|------|-----------------------------------------------|
| ( )| Logical grouping |
|------|-----------------------------------------------|
| .| Any single character |
|------|-----------------------------------------------|
| * | Zero or more instances |
|------|-----------------------------------------------|
| + | One or more instance |
|------|-----------------------------------------------|
| ? | Zero or one instance |
|------|-----------------------------------------------|
| _ | Comma, open or close brace, open or close |
| | parentheses, start or end of string, or space |
+------------------------------------------------------+
Some commonly used regular expressions include:
+-------------+---------------------------+
| Expression | Meaning |
|-------------+---------------------------|
| .* | Anything |
|-------------+---------------------------|
| ^$ | Locally originated routes |
|-------------+---------------------------|
2. February 28, 2012 [MUST HAVE REGULAR EXPRESSION PATTERNS]
| ^100_| Learned from AS100 |
|-------------+---------------------------|
| _100$ | Originated in AS100 |
|-------------+---------------------------|
| _100_| Any instance of AS100 |
|-------------+---------------------------|
| ^[0-9]+$| Directly connected ASes|
+-------------+---------------------------+
Let’s break some of the above expressions down step-by-step. The first one “.*” says to match any single character
(“.”), and then find zero or more instances of that single character (“*”). This means zero or more instances or any
character, which effectively means anything.
The next string “^$” says to match the beginning of the string (“^”), and then immediately match the end of the string
(“$”). This means that the string is null. Within the scope of BGP the only time that the AS-Path is null is when you
are looking at a route within your own AS that you or one of your iBGP peers has originated. Hence this matches
locally originated routes.
The next string “^100_” says to match the beginning of the string (“^”), the literal characters 100, and then a comma,
an open or close brace, an open or close, a parentheses, the start or end of the string, or a space (“_”). This means
that the string must start with the number 100 followed by any non-alphanumeric character. In the scope of BGP this
means that routes which are learned from the AS 100 will be matched, as 100 will be the first AS in the path when AS
100 is sending us routes.
The next string “_100$” is the exact opposite of the previous one. This string says to start with any non-alphanumeric
character (“_”), followed by the literal characters 100, followed by the end of the string (“$”). This means that AS 100
is the last AS in the path, or in other words that the prefix in question was originated by AS 100.
The next string “_100_” is the combination of the two previous strings with some extra matches. This string means
that the literal characters 100 are set between any two non-alphanumeric characters. The first of these could be the
start of the string, which would match routes learned from AS 100, while the second of these could be the end of the
string, which would match routes originated in AS 100. Another case could be that the underscores represent
spaces, in which the string would match any other AS path information as long as “ 100 ” is included somewhere.
This would match any routes which transit AS 100, and therefore “_ASN_” is generally meant to match routes that
transit a particular AS as defined by the number “ASN”.
The final string “^[0-9]+$” is a little more complicated match. Immediately we can see that the string starts (“^”), and
we can see later that it ends (“$”). In the middle we see a range of numbers 0-9 in brackets, followed by the plus sign.
The numbers in brackets mean that any number from zero to nine can be matched, or in other words, any number.
Next we have the plus sign which means one or more instances. This string “[0-9]+” therefore means one or more
instance of any number, or in other words any number including numbers with multiple characters (i.e. 1, 12, 123,
3. February 28, 2012 [MUST HAVE REGULAR EXPRESSION PATTERNS]
1234, 12345678, etc.). When we combine these all together this string means routes originated in any directly
connected single AS, or in other words, the routes directly originated by the peers of your AS.
Now let’s look at a more complicated match, and using the above character patterns we will see how we can
construct the expression step by step. Suppose we have the following topology below, where we are looking at the
network from the perspective of AS 100.
+--------+ +--------+ +--------+ +--------+
| AS 200 |-| AS 201 |-| AS 202 |-| AS 203 |
+--------+ +--------+ +--------+ +--------+
+--------+ +--------+ +--------+
| AS 300 |-| AS 301 |-| AS 302 |
+--------+ +--------+ +--------+ -+--------+
>--| AS 100 |
+--------+ +--------+ / -+--------+
| AS 400 |-| AS 401 | / /
+--------+ +--------+/ /
/
+--------+ /
| AS 500 |/
+--------+
AS 100 peers with ASes 203, 302, 401, and 500, who each have peers as diagramed above. AS 100 wants to match
routes originated from its directly connected customers (ASes 203, 302, 401, and 500) in addition to routes originated
from their directly connected customers (ASes 202, 301, and 400). The easiest way to create this regular expression
would be to think about what we are first trying to match, and then write out all possibilities of these matches. In our
case these possibilities are:
203
203 202
302
302 301
401
401 400
500
Now we could simply create an expression with multiple lines (7 lines to be exact) that would match all of the possible
AS paths, but suppose that AS 100 wants to keep this match as flexible as possible so that it will apply to any other
ASes in the future. Now let’s try to generalize the above AS-Path information into a regex.
First off we know that each of the matches is going to start and going to end. This means that the first character we
will have is “^” and the last character is “$”. Next we know that between the “^” and “$” there will be either one AS or
4. February 28, 2012 [MUST HAVE REGULAR EXPRESSION PATTERNS]
two ASes. We don’t necessarily know what numbers these ASes will be, so for the time being let’s use the
placeholder “X”. Based on this our new possible matches are:
^X$
^X X$
Next let’s reason out what X can represent. Since X is only one single AS, there will be no spaces, commas,
parentheses, or any other special type characters. In other words, X must be a number. However, since we don’t
know what the exact path is, we must take into account that X may be a number with more than one character (i.e.
10, 123, or 10101). This essentially equates to one or more instance of any number zero through nine. In regular
expression syntax our two matches would therefore now read:
^[0-9]+$
^[0-9]+ [0-9]+$
This expressions reads that we either have a number consisting of one or more characters zero through nine, or a
number consisting of one or more characters zero through nine followed by a space and then another number
consisting of one or more characters zero through nine. This brings our expression down to two lines as opposed to
our original seven, but let’s see how we can combine the above two as well. To combine them, first let us compare
what is different between them.
^[0-9]+$
^[0-9]+ [0-9]+$
From looking at the expressions it is evident that the sequence “ [0-9]+” is the difference. In the first case “ [0-9]+”
does not exist in the expression. In the second case “ [0-9]+” does exist in the expression. In other words, “ [0-9]+” is
either true or false. True or false (0 or 1) is represented by the character “?” in regex syntax. Therefore we can
reduce our expression to:
^[0-9]+ [0-9]+?$
At this point we run into a problem with the order of operations of the regex. As denoted above the question mark will
apply only to the plus sign, and not to the range [0-9]. Instead, we want the question mark to apply to the string “ [0-
9]+” as a whole. Therefore this string needs to be grouped together using parentheses. Parentheses are used in
regular expressions as simply a logical grouping. Therefore our final expression reduces to:
^[0-9]+( [0-9]+)?$
Note that to match a question mark in IOS, the escape sequence CTRL-Vor ESC-Qmust be entered first, otherwise
the IOS parser will interpret the question mark as an attempt to invoke the context sensitive help.