HardParsing
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>.
//
<div>content</div> / <span>text</p> / <b>bold</b> / <p>unmatched / plain text
Test cases
- <div>content</div>expect match
- <span>text</p>expect no match
- <b>bold</b>expect match
- <div><span>nested</span></div>expect match
- <p>unmatchedexpect no match
- plain textexpect no match
- <h1>Title</h1>expect match
How to Solve this Regex Challenge
To complete the Matching Tag Pair Finder challenge, you must write a regular expression pattern that satisfies all specified test cases.
Steps to Complete:
- Analyze the Requirements: Read the description and review the list of test cases below. Identify which strings must be matched (green markers) and which must be rejected (red markers).
- Draft Your Pattern: Enter your regex in the interactive editor. Use the provided Hint button if you get stuck.
- Verify: The test cases panel will update in real-time as you type, showing which strings match your current expression.
- Review the Solution: Once you successfully pass all test cases, review the explanation to understand the logic behind the solution.