133 regular expressions
From the notation itself to checks for email, dates and addresses. Every expression comes with examples that should match and examples that should not — and the test suite actually runs them.
Notation28
How to point at a single character. Everything else builds on these.
\da single digit\Danything but a digit\wa letter, digit or underscore\Wanything that is not a word character\sa whitespace character\Sanything but whitespace^.$any single character^[a-z]+$lowercase letters only^[A-Z]+$uppercase letters only^[A-Za-z0-9]+$letters and digits only^[^0-9]+$text with no digits at all^[가-힣]+$Hangul only^[ぁ-んァ-ヶー]+$kana only^[\u4e00-\u9fff]+$Chinese characters only^a\.b$a literal dot^a/b$a literal forward slash\ta tab character\na line break\r\na Windows line ending^\u00e9$a character written by code point^Hellotext that starts with this wordworld$text that ends with this word^cat$exactly this word and nothing else\bcat\bthe word on its own, not inside another\Bcatthe word only inside another word^cat$a match that ignores capitals^bthe start of each line, not just the text^a.b$any character, line breaks includedRepeats and groups17
How many times something repeats, and what counts as one unit.
^ab*c$none or many^ab+c$once or more^colou?r$a letter that may or may not be there^\d{4}$exactly four digits^\d{2,4}$between two and four digits^\d{2,}$two digits or more<.+?>one tag, taken as short as possible^<.+>$one chunk, taken as long as possible^(?:cat|dog)$either one of two words^(?:ab)+$a two-letter group, repeated^(\d{3})-(\d{4})$two parts caught separately^(?:\d{3}-)+\d{4}$grouping without catching^(?<year>\d{4})-(?<month>\d{2})$catching with a name attached(\w)\1the same character twice in a row\b(\w+)\s+\1\bthe same word typed twice^(?:https?://)?example\.com$an address with or without the scheme^(?:\d{1,3}\.){3}\d{1,3}$an address made of four partsLooking around8
Checks what sits before or after without consuming it. Useful for stacking conditions.
\d+(?= dollars)a number followed by a certain word^(?!admin$).+$anything except this one word(?<=\$)\d+a number preceded by a certain sign(?<!\$)\b\d+a number without that sign in front^(?=.*[A-Z])(?=.*\d)(?=.*[a-z]).{8,}$eight or more characters with upper, lower and a digit^(?!.* ).+$text with no double space anywhere^(?=.*@).+$text that must contain this sign\B(?=(\d{3})+(?!\d))the spot where a thousands comma goesWhole-string checks44
Anchored at both ends, so the whole string has to match. This is what input validation uses.
^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+$an email address^https?://[^\s/$.?#][^\s]*$a web address^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$a domain name^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)$an IPv4 address^(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}$an IPv6 address written out in full^(?:[0-9a-f]{2}[:-]){5}[0-9a-f]{2}$a MAC address^(?:6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]?\d{1,4})$a port number^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$a UUID^#(?:[0-9a-f]{3}|[0-9a-f]{6})$a hex colour code^rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\)$an rgb() colour value^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$a date in ISO form^(?:0[1-9]|[12]\d|3[01])/(?:0[1-9]|1[0-2])/\d{4}$a date written with slashes^(?:[01]\d|2[0-3]):[0-5]\d$a time on the 24-hour clock^(?:0?[1-9]|1[0-2]):[0-5]\d\s?(?:am|pm)$a time with am or pm^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$a full ISO timestamp^P(?=\d|T\d)(?:\d+Y)?(?:\d+M)?(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+S)?)?$an ISO duration^\d+\.\d+\.\d+(?:-[0-9a-z.-]+)?(?:\+[0-9a-z.-]+)?$a semantic version number^\d+$a whole number with no sign^[+-]?\d+$a whole number that may carry a sign^-?\d+(?:\.\d+)?$a number that may have a decimal part^-?\d+(?:\.\d+)?[eE][+-]?\d+$a number in scientific notation^(?:100(?:\.0+)?|\d{1,2}(?:\.\d+)?)%$a percentage from 0 to 100^\d{1,3}(?:,\d{3})*$a number grouped with commas^[$€£¥₩]\s?\d{1,3}(?:,\d{3})*(?:\.\d{2})?$an amount with a currency sign^[0-9a-f]+$a hexadecimal string^[01]+$a string of nothing but 0 and 1^[0-7]+$an octal string^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$a base64-encoded string^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$a JWT split by two dots^\+[1-9]\d{7,14}$a phone number in international form^[a-z][a-z0-9_]{2,15}$a username that starts with a letter^[a-z0-9]+(?:-[a-z0-9]+)*$a URL slug^[^\\/:*?"<>|]+\.[a-z0-9]+$a file name with an extension^.+\.(?:jpe?g|png|gif|webp|avif|svg)$an image file extension^/(?:[^/\0]+/)*[^/\0]*$a Unix-style path^[A-Za-z]:\\(?:[^\\/:*?"<>|]+\\)*[^\\/:*?"<>|]*$a Windows path^</?[a-z][a-z0-9]*(?:\s[^<>]*)?/?>$a single HTML tag^\.-?[_a-z][_a-z0-9-]*$a CSS class selector^M{0,3}(?:CM|CD|D?C{0,3})(?:XC|XL|L?X{0,3})(?:IX|IV|V?I{0,3})$a Roman numeral^-?(?:90(?:\.0+)?|[1-8]?\d(?:\.\d+)?)$a latitude value^-?(?:180(?:\.0+)?|1[0-7]\d(?:\.\d+)?|\d{1,2}(?:\.\d+)?)$a longitude value^(?:0|[1-9]\d*)$a number with no leading zero^\d*[02468]$an even number^\s*$a blank lineFinding and cleaning36
For picking out or deleting just the part you need from a larger text.
\s+$space left at the end of a line^\s+space at the start of a line^\s+|\s+$space at either end\s{2,}two or more spaces in a row\n\s*\nan empty line between two lines\D+everything that is not a digit[^\x00-\x7F]a character outside ASCII[\x00-\x1F]an invisible control character</?[^>]+>the HTML tags in a text<!--[\s\S]*?-->an HTML comment//.*$a comment that starts with two slashes/\*[\s\S]*?\*/a comment that spans lines"[^"\\]*(?:\\.[^"\\]*)*"text inside double quotes'[^'\\]*(?:\\.[^'\\]*)*'text inside single quotes\[([^\]]+)\]\(([^)]+)\)a Markdown link^#{1,6}\s+.+$a Markdown heading line(?:^|\s)#([a-z0-9_]+)a hashtag(?:^|\s)@([a-z0-9_]{2,})an @ mention[?&]([^=&]+)=([^&]*)a query parameter in a URLhttps?://[^\s<>"]+a URL sitting inside ordinary text^https?://([^/:?#]+)just the domain out of a URL\.([a-z0-9]+)$the extension of a file name(?<=[a-z0-9])(?=[A-Z])the seam between words in camelCase_([a-z])the letter that follows an underscore-([a-z])the letter that follows a hyphen(?:^|,)("(?:[^"]|"")*"|[^,]+)one comma-separated field^([^=]+)=(.*)$a name and value split by an equals sign^\s*(\S+)the first word(\S+)\s*$the last word\d+runs of digits inside a text\b\w+\beach word, one by one\[([^\]]*)\]what sits inside square brackets\(([^)]*)\)what sits inside round brackets[\uD800-\uDBFF][\uDC00-\uDFFF]an emoji that takes two code units(.)\1{2,}the same character three times or more,\s*([}\]])a comma left before a closing bracketHow to read this
- With ^ and $ around it, the whole string must match; without them the match can sit anywhere. Always anchor an expression you use for validation.
- Round brackets ( ) capture what they wrap. When you only need grouping, write (?: ) so the numbering of later groups does not shift.
- Every expression here is checked against its examples. Even so, "looks like an email" and "is a real inbox" remain different questions.
- Nested open-ended repeats such as (a+)+ can blow up on certain inputs. Look for that shape before pasting someone else’s expression into your code.
Frequently asked questions
Q. What is a regular expression?
A small language for describing a shape to look for in text. Writing \d{4} instead of "four digits" lets a program find every place that shape occurs. JavaScript, Python, Java and most other languages share nearly the same notation.
Q. Why is the email check so short?
A pattern covering the full specification runs to thousands of characters and still cannot tell you whether the mailbox exists. Catching typos is what a regular expression can do; the only real check is sending a confirmation message.
Q. Why do patterns differ between languages?
The core is shared but the details are not. JavaScript has no \A, and Python needs re.MULTILINE switched on separately. Everything here is written to run as-is in JavaScript.
Q. What does it mean that a pattern can be slow?
When open-ended repeats nest, as in (a+)+, the number of ways to backtrack explodes on input that does not match. A short string can then take seconds, which is dangerous on a server.
Q. Can I trust the patterns here?
Each one is stored with examples that must match and examples that must not, and the test suite runs all 133 for real. The examples you see on the page are the same ones the tests use, so a description cannot drift away from its pattern.