0

I'm aware of the issues with using regex to find html, but I'm mainly wondering if I can improve this regex for more findings:

//Looking for <div class="glance_details">
$regex = "/<\\s*div\\s+[^>]*class=['\"][^'\"]*glance_details[^'\"]*['\"]/i";

Perhaps it's safer just to look for glance_details?

EDIT:

RegEx match open tags except XHTML self-contained tags

I have given in to the scourge.

Community
  • 1
  • 1
Algernop K.
  • 477
  • 2
  • 19
  • Possible duplicate of [RegEx match open tags except XHTML self-contained tags](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – mech Jan 12 '16 at 21:37
  • What about using a parser? – chris85 Jan 12 '16 at 21:38
  • @chris85 The parsers I know how to use (e.g. Simple DOM HTML Parser) are too slow! Getting all matches is not important, getting as many matches as possible using regex is better in my case.. – Algernop K. Jan 12 '16 at 21:41
  • Can you show your parser usage? Is that class always on its own? Can you provide an example of where this fails? – chris85 Jan 12 '16 at 21:42
  • @chris85 I can show you a similar case. Just one second please. – Algernop K. Jan 12 '16 at 21:44
  • 1
    Simple DOM HTML Parser is slow indeed (and useless), but the built-in combo DOMDocument/DOMXPath is faster if you take the time to learn it. – Casimir et Hippolyte Jan 12 '16 at 21:48
  • @chris85 It seems I cannot do that.. In rage I deleted every evidence of it ever failing.. – Algernop K. Jan 12 '16 at 21:49
  • @CasimiretHippolyte I did try and get that functioning once, but I failed so miserably that I didn't even bother seeking assistance, haha. I might try again, but it's hard to find motivation for it knowing that my regex is (almost) working. – Algernop K. Jan 12 '16 at 21:52
  • If you want continue in programming, you must learn the DOM and XPath. It isn't simple and it takes time, but once you have learned them, you can use them in all languages (like other XML technologies) – Casimir et Hippolyte Jan 12 '16 at 21:57
  • @CasimiretHippolyte Thanks I'll think of that. I'm still very much a newb but at some point the world will probably call for me to learn that. I'll get there – Algernop K. Jan 12 '16 at 22:05

0 Answers0