Jump to content
Sign in to follow this  
mstdmstdd

Get only headers with end tag

Recommended Posts

  Hello,
In this small example
https://regex101.com/r/KF7Ymb/1

I hoped to get only headers with end tag, without opening tag.
But I got

<h1>header 1</h1>

as result and seems expression

(?<!<h[1-6]>)

does not work. Which is the right way?

Thanks!

Share this post


Link to post
Share on other sites

The right way is to understand that HTML is an actual language. This means you need an actual parser, not a bunch of half-assed regexes you've come up with.

Edited by Jacques1
  • Like 1

Share this post


Link to post
Share on other sites

Strongly agree. Use the DOM or possibly simplexml for these tasks. Regex is not the right tool for the job.

Share this post


Link to post
Share on other sites

You are right from your point.

But actually that was not not a real task but mastering of regex.

I made some examples in tutorial, trying to play and extend examples...

So has it decision?

Share this post


Link to post
Share on other sites

What's the point of practicing wrong approaches? There are plenty of useful exercises, so why waste time on something that isn't going to help you in the real world?

 

In any case, the regex is badly messed up, and you don't seem to understand the concept behind lookaround patterns. Look that up, then try a simple example and make sure you actually know what's going on.

  • Like 1

Share this post


Link to post
Share on other sites

Could you please give refs to some useful exercises ?

Which could be used in real tasks...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.