0

I was using the PHP Simple Dom library which was working perfectly in PHP 5.6.x. Now, we are migrating our system from this version to PHP 7.4.5 and unfortunately this library has badly paused us.

After hours of troubleshooting, I did figured this out that this expression is causing the reason. This is old standard PHP 5 based regular expression which needs to be converted into the PHP 7.x.

/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-:]+)(?:([!*^$]?=)["']?(.*?)["']?)?\])?([\/, ]+)/is

Can anyone please help on it?

Just got stuck in big hell of issue. Please help Thanks in advance

Saeed Afzal
  • 368
  • 1
  • 5
  • 18
  • How was that being used? What errors do you receive, what strings are going into it? I don't follow how a regex and a parser work together. I don't use simple dom though, https://www.php.net/manual/en/class.domdocument.php. – user3783243 Apr 26 '20 at 05:00
  • This library is used to parse the Html pages. So the expression mentioned in above description is basically based on the old PCRE standards which isn't working in PHP 7.x because PHP 7.x works with PCRE2 which is more strict in validating the patterns. - That's the problem. I think I found the solution here but not tested yet! https://php.watch/versions/7.3/pcre2 – Saeed Afzal Apr 26 '20 at 05:07
  • Oh, you should add the information to the question. The `-` should never be in the middle of a character class unless it is making a range. It should be first or last otherwise. – user3783243 Apr 26 '20 at 05:12
  • Sorry, I couldn't understand this. I have made so much attempts but got no success. It has waste so much hours and haven't made any progress. Can you please help me sending the correct one? – Saeed Afzal Apr 26 '20 at 05:25
  • 1
    Well, you *are* there, my answer is the solution. Move `-` to the end of the 2 character classes, `[\w-:]` => `[\w:-]` and `[\w-:\*]` => `[\w:*-]`. Use `/([\w:*-]*)(?:#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w:-]+)(?:([!*^$]?=)["']?(.*?)["']?)?])?([\/, ]+)/` - no `is` at the end needed. Although I have no idea why you have `(!?[\w:-]+)`, it looks very suspicious. – Wiktor Stribiżew Apr 26 '20 at 09:34
  • Tried but still not getting the results. But I appreciate for helping me on it. - Thanks – Saeed Afzal Apr 26 '20 at 13:13

0 Answers0