# Regex 101

### Online resources

Online resources for regular expressions:

| Website                 | Description                                                                                                                             |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| <https://regex101.com/> | <p>Online testing of regex, supporting different regex types / languages.<br><br>Detailed explanation of the different regex parts.</p> |

### Regex basic cheatsheet

| keyword                                                    | Description                                                                         |
| ---------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `a`                                                        | Matches the character a.                                                            |
| `a\|b`                                                     | Matches either the character a or b.                                                |
| `a?`                                                       | Matches zero or one a.                                                              |
| `a*`                                                       | Matches zero or more a.                                                             |
| `a+`                                                       | Matches one or more a, as many times as possible, giving back as needed (greedy).   |
| `a+?`                                                      | Matches one or more a, as few times as possible, expanding as needed (lazy).        |
| `a{5}`                                                     | Matches exactly 5 consecutive a.                                                    |
| `a{5-10}`                                                  | Matches between 5 to 10 (inclusive) consecutive a.                                  |
| `a{5,}`                                                    | Matches 5 or more consecutive a.                                                    |
| `.`                                                        | Matches any single character.                                                       |
| `\s`                                                       | Matches any single space, tab or newline character.                                 |
| `\S`                                                       | Matches any single character that is not a space, tab or newline.                   |
| <p><code>\d</code><br><br><code>\[0-9]</code></p>          | Matches any single digit character.                                                 |
| <p><code>\D</code><br><br><code>\[^0-9]</code></p>         | Matches any single character that is not a digit.                                   |
| <p><code>\w</code><br><br><code>\[a-zA-Z0-9\_]</code></p>  | Matches any single letter, digit, or underscore.                                    |
| <p><code>\W</code><br><br><code>\[^a-zA-Z0-9\_]</code></p> | Matches any single any single character that is not a letter, digit, or underscore. |
| `^`                                                        | Matches the start of the string.                                                    |
| `^abc`                                                     | Matches a string starting by abc.                                                   |
| `$`                                                        | Matches the end of the string.                                                      |
| `xyz$`                                                     | Matches a string ending by xyz.                                                     |
| `[xyz]`                                                    | Matches a single character among x, y, or z.                                        |
| `[^xyz]`                                                   | Matches any character except for x, y or z.                                         |
| `[a-z]`                                                    | Matches a single character in the range a to z.                                     |
| `[a-zA-Z]`                                                 | Matches a single character in the range a to z or A to Z.                           |
| `[^a-z]`                                                   | Matches any character except those in the a to z range.                             |

### Regex examples

| Regex                                                                                                  | Description                                            |
| ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------ |
| `((25[0-5]\|2[0-4][0-9]\|1?[0-9][0-9]?)\\.){3}(25[0-5]\|2[0-4][0-9]\|[01]?[0-9][0-9]?)(:[1-65535]\D)?` | Matches an IPv4 address, with an eventual port number. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.qazeer.io/miscellaneous/regex101.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
