Pulling dates out of a log file, and the pattern that freezes
Regular expressions are easiest to learn on a real job. Say you have a log with lines like "2024-03-15 09:12:44 ERROR payment failed for order 8812" and you want every date. A first try is \d{4}-\d{2}-\d{2}: four digits, a dash, two digits, a dash, two digits. With the g flag on, the tester highlights each date and lists where it starts. Without g, it finds only the first one, because that is what JavaScript does.
Now you want the year, month and day separately. Wrap each part in parentheses: (\d{4})-(\d{2})-(\d{2}). Each match now has three groups, shown as 1, 2 and 3 in the table. Better, give them names: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}). Switch to Extract and pick Group <year>, and you get a list of years, one per line, ready to paste into a spreadsheet. Switch to Replace and type lt;day>/lt;month>/lt;year>, and every date in the text is rewritten as 15/03/2024.
The pattern still matches things that are not dates, such as 9999-99-99, or the middle of a longer number like 12024-03-155. Add word boundaries to stop the second problem: \b(\d{4})-(\d{2})-(\d{2})\b. The first problem is better solved after matching. A regex that only accepts valid calendar dates is long and hard to read, and it still cannot know that 2023-02-29 does not exist. Match the shape with the regex, then check the value in code.
Some patterns look fine and then hang. Try (\w+\s?)+$ against a long line of words that ends with a full stop. The engine first matches the whole line, fails at the full stop, then backs up and tries every other way to divide the words between the inner \w+ and the outer +. The number of ways doubles with each character, so 30 characters can take minutes. In a web server this is a real attack, called ReDoS. Here the run is stopped after one second and you are told why. The fix is to make each character belong to the pattern one way only, for example ^(\w+\s)*\w+$ or simply ^[\w\s]+$.
This tester has limits. It only speaks JavaScript regex, so a pattern copied from Python or PHP may need changes: Python’s (?P<name>...) becomes (?<name>...), and possessive quantifiers such as a++ do not exist. The one-second limit applies to the whole run, so a fair pattern over a very large text can also hit it. The highlight shows the first 1,000 matches and the table the first 200, although counts and outputs use them all.