mstdmstdd Posted June 27, 2017 Share Posted June 27, 2017 Hello,In this small examplehttps://regex101.com/r/KF7Ymb/1I 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! Quote Link to comment https://forums.phpfreaks.com/topic/304211-get-only-headers-with-end-tag/ Share on other sites More sharing options...
Jacques1 Posted June 27, 2017 Share Posted June 27, 2017 (edited) 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 June 27, 2017 by Jacques1 1 Quote Link to comment https://forums.phpfreaks.com/topic/304211-get-only-headers-with-end-tag/#findComment-1547751 Share on other sites More sharing options...
gizmola Posted June 27, 2017 Share Posted June 27, 2017 Strongly agree. Use the DOM or possibly simplexml for these tasks. Regex is not the right tool for the job. Quote Link to comment https://forums.phpfreaks.com/topic/304211-get-only-headers-with-end-tag/#findComment-1547778 Share on other sites More sharing options...
mstdmstdd Posted June 28, 2017 Author Share Posted June 28, 2017 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? Quote Link to comment https://forums.phpfreaks.com/topic/304211-get-only-headers-with-end-tag/#findComment-1547789 Share on other sites More sharing options...
Jacques1 Posted June 28, 2017 Share Posted June 28, 2017 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/304211-get-only-headers-with-end-tag/#findComment-1547791 Share on other sites More sharing options...
mstdmstdd Posted July 3, 2017 Author Share Posted July 3, 2017 Could you please give refs to some useful exercises ? Which could be used in real tasks... Quote Link to comment https://forums.phpfreaks.com/topic/304211-get-only-headers-with-end-tag/#findComment-1547928 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.