Loading devShakib…
Test regular expressions with live highlighting, capture groups and a replace preview.
Most regular expressions fail on the same two things: greediness and anchoring. `.*` takes as much as it possibly can and then gives characters back only when forced, which is why a pattern written to match one tag swallows the rest of the line. The lazy form `.*?` inverts that, and is usually what was meant.
Capture groups are where a working pattern becomes a useful one, since matching only tells you something is there and groups tell you what. Numbering counts opening parentheses left to right, including the ones you added purely for grouping — which is what silently shifts every index when you wrap a section in brackets later.
A pattern worth testing before it ships is one with nested quantifiers. Certain shapes make the engine explore an exponential number of paths on input that nearly matches, and a regex that runs instantly on your examples can hang a server on a string a few characters longer.