Best Way to Get All HTML Tags Regex? Need Help with a Reliable Pattern!

20 Replies, 1553 Views

Hey! Regex for HTML can be a pain, honestly. I’ve used `<(\w+)[^>]*>(.*?)<\/\1>` before, and it works decently for most tags. It’s not perfect, but it handles basic stuff like `<div>` and `<p>`. For self-closing tags, you might need to tweak it a bit.

If you’re dealing with messy HTML, I’d recommend using a proper HTML parser instead of regex. Python’s BeautifulSoup or JS’s DOMParser are way more reliable for this kind of thing.

Good luck!

Messages In This Thread



Users browsing this thread: 1 Guest(s)