There are many instances in which we need to parse interface configs to fetch useful information. For example, from a list of devices, find all the interfaces that are trunk. Another example could be to find all the interfaces that are admin-shutdown (shutdown on the router), or even fetch the IP address configurations from interfaces.
There might be instances wherein we need to find out whether particular IP addresses or subnets are configured on the router.
A good way to extract any information is using regex. Regex is term that is used to match a particular pattern and either fetch the matched pattern or validate whether a certain pattern is present in the parsed text.
Here are the most basic and important regexes that are used in Python:
. | Match any character except newline |
^ | Match the start of the string |
$ | Match the end of the string |