Hello,
sometimes I extract several values out of large HTML-Files/Strings. Now i wonder which is better for performance: Put everything in one regular expression, or make one matching per value.
For example: I have a a huge string which has values for "langid=", "date=", and "userid=". These values are anywhere in the huge string. Now what is more performant on PCRE's:
preg_match('/langid=(\d+).*?date=([0-9. ]+).*?userid=(\d+)/', $largestring, $results); // METHOD 1
or one preg match for every value (METHOD 2):
preg_match('/langid=(\d+)/', $largestring, $lang);
preg_match('/date=([0-9. ]+)/', $largestring, $date);
preg_match('/userid=(\d+)/', $largestring, $user);
With Method 1 everything gets extracted in "one turn", but the internal steps are doubled because of the backtracking (if i see it correctly), and with Method 2 the engine starts from the beginning everytime. Is this right? What is more performant in your eyes, and why?