Regex Challenges
20 hands-on puzzles across four difficulty levels. Progress is saved locally in your browser.
Hex Color Finder
Write a regex that matches valid hexadecimal color codes, either the short form (#fff) or the long form (#ffffff). The pattern must reject codes with the wrong number of digits or non-hex characters.
Valid Username Checker
Write a regex that validates usernames: they must start with a letter, be 3-16 characters total, and contain only letters, digits, or underscores.
Digit Sequence Extractor
Write a regex that detects whether a piece of text contains a run of one or more digits, so it could be used to pull numbers like order counts or prices out of a sentence.
Phone Number Format Check
Write a regex that validates US-style phone numbers written strictly as three digits, a dash, three digits, a dash, then four digits (e.g. 123-456-7890).
Alphabetic Word Matcher
Write a regex that matches strings made up of alphabetic letters only, with no digits, punctuation, or spaces allowed anywhere.
Leading/Trailing Whitespace Finder
Write a regex you could pass to .replace() to detect whitespace that sits at the very start or very end of a string (the kind you'd want to trim), while ignoring whitespace in the middle of the text.
Basic Quoted String Matcher
Write a regex that matches a string fully wrapped in double quotes, where the content between the quotes contains no quote characters at all. This is a simplified version that doesn't need to handle escaped quotes.
Key=Value Pair Matcher
Write a regex that matches simple configuration lines in the form key=value, where both the key and value consist of word characters only, with exactly one equals sign and no missing sides.
Extra Space Detector
Write a regex intended for use with .replace() to detect runs of two or more consecutive spaces in a string, so they could be collapsed down to a single space.
ISO Date Format Checker
Write a regex that checks whether a string follows the YYYY-MM-DD digit layout (four digits, dash, two digits, dash, two digits). It only needs to check the shape, not whether the date is a real calendar date.
Simple HTML Tag Matcher
Write a regex that detects simple HTML tags like <div>, <p>, or a closing </span>, without worrying about attributes inside the tag.
24-Hour Time Validator
Write a regex that validates times in 24-hour HH:MM format, where hours must be 00-23 and minutes must be 00-59, with leading zeros required.
Repeated Word Detector
Write a regex that detects when the same word appears twice in a row separated by whitespace, such as 'the the' or 'is is', a common typo in written text.
Quoted String With Escapes
Write a regex that matches a double-quoted string where escaped quotes (\") inside the string are allowed and don't end the match early, but an unescaped quote in the middle should not be permitted.
Password Strength Validator
Write a regex that validates a password requiring at least one lowercase letter, one uppercase letter, one digit, one symbol, and a minimum length of 8 characters.
Unmarked Number Finder
Write a regex that matches whole numbers in a sentence only when they are NOT immediately preceded by a dollar sign, so plain quantities are found but prices are ignored.
Matching Tag Pair Finder
Write a regex that matches an HTML element only when its closing tag matches its opening tag name, such as <div>...</div>, rejecting mismatched pairs like <span>...</p>.
Strict IPv4 Address Validator
Write a regex that validates an IPv4 address, ensuring each of the four dot-separated octets is a real number between 0 and 255, rather than just any string of digits.
Ultra-Strong Password Validator
Write a regex that validates a password between 10 and 24 characters that contains at least one uppercase letter, one lowercase letter, one digit, one symbol, and has no single character repeated three or more times in a row (like 'aaa' or '111').
Currency-and-Percent-Free Number Finder
Write a regex that matches a whole number only when it is neither immediately preceded by a dollar sign nor immediately followed by a percent sign, isolating plain quantities from prices and percentages in the same sentence.