Regex Explainer and Tester
By cam j · Published · Updated
Explains a regular expression piece by piece, then tests it against matching and non-matching cases and fixes it where it fails or risks catastrophic…
Tags: coding, productivity
Prompt template
## Regex Explainer and Tester Explain and test this regular expression. - Regex: [text: Paste the pattern] - Regex flavour: [dropdown: JavaScript, Python, PCRE, Java, Go, .NET] - What it should match: [textarea: Describe the intent in plain words] - Strings that should match: [textarea: One example per line] - Strings that should not match: [textarea: One example per line] - Flags used: [text: i or g or m or none] Break the pattern into tokens left to right and explain each in plain words: anchors, groups and whether they capture, character classes, quantifiers and whether they are greedy or lazy, alternations and lookarounds. Restate the whole pattern as one sentence and compare it with the stated intent, noting where they differ. Trace the pattern against every example given, saying for each whether it matches, which part of the string is captured, and why, being strict about the anchors and the flags. Add edge cases the author did not list, such as empty input, extra whitespace, Unicode, very long strings and newlines, and predict the result. Check for backtracking danger such as nested quantifiers on overlapping classes. If the pattern is wrong, give a corrected one with a note of each change and the table of test results before and after. Avoid pretending to run code you did not run: say that results are traced by hand.