> For the complete documentation index, see [llms.txt](https://cisco.microcisco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cisco.microcisco.com/icnd-1/routing/bgp/regular-expressions.md).

# Regular Expressions

Asterisk on STEROIDS !!

## Resources

## Introduction

This introduction will enable us to do the following:

* Describe Regular Expressions
* Use regular expressions to match basic patterns
* Describe RegEx Metacharacter
* Practise Regular Expressions using <https://regex101.com> or <https://regexr.com>

|    | METACHARACTER | METACHARACTER NAME | MEANING                                                                                                                                           |
| -- | ------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| 1  | **^**         | caret              | Matches the beginning of the string, or the beginning of a line if the multiline flag (`m`) is enabled. This matches a position, not a character. |
| 2  | **$**         | dollar sign        | Denotes the END of a regular expression or ending of a line                                                                                       |
| 3  | **\[ ]**      | square bracket     | Specifies a range of characters you wish to match                                                                                                 |
| 4  | **( )**       | parenthesis        | Check for a string. Create and store variables                                                                                                    |
| 5  | **?**         | question mark      | Check for zero or one occurrence of the preceding character .... zero or one instance                                                             |
| 6  | **+**         | plus sign          | Check for one or more occurrence of the preceding character .....one or more instances                                                            |
| 7  | **\***        | multiply sign      | check for any number of occurrences (including zero occurrence) of the preceding character ... zero or more instances                             |
| 8  | **.**         | dot                | check for a single character which is not the ending of a line......Any single character                                                          |
| 9  | **\|**        | pipe               | Logical OR                                                                                                                                        |
| 10 | **\\**        | escaping character | Escape from the normal way a subsequent character is interpreted                                                                                  |
| 11 | **!**         | exclamation mark   | Logical NOT                                                                                                                                       |
| 12 | **{ }**       | curly brackets     | Repeat preceding character                                                                                                                        |
| 13 | -             | dash               | Used to specify range ie \[0-9]                                                                                                                   |

```
The fat cat ran down the street.
It was seraching for a mouse to eat.
```

Using the websites above (eg[ https://regexr.com](https://regexr.com) ) in the text field we have written some text to be searched by regex with the global and multiline selected. I will remove the multi-line option to keep it as close to normal regex as possible.

![](https://4011257951-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LtfmTuncdFr6DnNyt_b%2F-MK793ytk-vxcP6HmoqR%2F-MK7LZsWVv0gOnuOjBEY%2Fimage.png?alt=media\&token=85082455-cee6-4803-b6af-3c59ac0ef3cc)

## What is RegEx

RegEx is the shortened word for Regular Expression. A regular expression is a way of searching through text files - such as logfiles etc. in an efficient and painless way as possible. We can also do advanced 'find and replace.

`^a . . .s$`

The caret means "at the beginning
