Regex generator
Describe what to match. You get the pattern, what each part does, and what it will miss.
A worked example
“Match a UK postcode”
[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}One or two letters for the area, then a digit, then an optional third character that can be either a letter or a digit, then an optional space, then the inward code of a digit and two letters. The optional space is what lets it match a postcode whether or not somebody typed one.
What it assumes
- Case sensitive as written. Add the i flag, or uppercase the input first, or it will miss every lowercase postcode.
- Matches the shape of a postcode, not a real one. XX9 9XX passes. Only a lookup against the Royal Mail address file can tell you whether a postcode exists.
- Unanchored, so it finds a postcode inside a longer string. Wrap it in ^ and $ if the whole field must be a postcode and nothing else.
01
It tells you what it does not match.
That is where a regular expression is always wrong. A pattern is easy to check against the examples you thought of and impossible to check against the ones you did not, so the caveats name them.
02
Readable beats clever.
A pattern you can still understand in six months is worth more than one three characters shorter. Nested quantifiers that can backtrack catastrophically are avoided rather than golfed.
03
Flavours differ more than people expect.
Lookbehind, named groups and Unicode classes are not available everywhere. Picking your language changes the pattern rather than leaving you to find out at runtime.
Questions people ask
Which flavour should I choose?
The one your code runs in. JavaScript has no lookbehind in older engines, Python names groups differently, and RE2, which is what Go and BigQuery use, has no backreferences or lookaround at all. The same pattern is not portable across them.
Why does the pattern come back without slashes?
Because the delimiters are your language's, not the pattern's. You get the expression itself and any flags it needs listed in a caveat, so you can wrap it however your code expects.
Can I use this in Excel or Google Sheets?
In Google Sheets, yes, through REGEXMATCH, REGEXEXTRACT and REGEXREPLACE, which use RE2. Excel only has regular expressions in recent Microsoft 365 builds, so check which version you are on before relying on them.
Is a regular expression the right tool here?
Often not. Email addresses, HTML and dates all have well known parsers that are more correct than any pattern, and where that is the case you will be told so rather than handed a two hundred character expression.
When it is a whole file
A formula fixes one column. If what you actually have is four exports and a question, drop them here and you get the cleaned data, the analysis and the charts back.
No account needed to start. You only pay when you like what you see.