diff options
author | 2022-03-12 23:55:27 -0500 | |
---|---|---|
committer | 2022-03-13 04:55:27 +0000 | |
commit | 37ff9d2b9f4e131d5d84afac5e5aa529020f0b53 (patch) | |
tree | 3d52af451a37b26cf8dd203cc7b8ad05e9a50da2 | |
parent | Merge pull request #1680 from python-discord/feat/mod/1664/resend-infraction (diff) |
Add regex tag (#2109)
Co-authored-by: ToxicKidz <[email protected]>
Co-authored-by: Xithrius <[email protected]>
-rw-r--r-- | bot/resources/tags/regex.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/bot/resources/tags/regex.md b/bot/resources/tags/regex.md new file mode 100644 index 000000000..35fee45a9 --- /dev/null +++ b/bot/resources/tags/regex.md @@ -0,0 +1,15 @@ +**Regular expressions** +Regular expressions (regex) are a tool for finding patterns in strings. The standard library's `re` module defines functions for using regex patterns. + +**Example** +We can use regex to pull out all the numbers in a sentence: +```py +>>> import re +>>> x = "On Oct 18 1963 a cat was launched aboard rocket #47" +>>> regex_pattern = r"[0-9]{1,3}" # Matches 1-3 digits +>>> re.findall(regex_pattern, foo) +['18', '196', '3', '47'] # Notice the year is cut off +``` +**See Also** +• [The re docs](https://docs.python.org/3/library/re.html) - for functions that use regex +• [regex101.com](https://regex101.com) - an interactive site for testing your regular expression |