Solution:
It depends on your case: if you’re trying to do something fairly basic (eg: search for a string, replace a substring with something else), then the regular string functions are the way to go. If you want to do something more complicated (eg: search for IP addresses), then the Regex functions are definitely a better choice.
I haven’t profiled regexes so I can’t say that they’ll be faster at runtime, but I can tell you that the extra time spent hacking together the equivalent using the basic functions wouldn’t be worth it.
Edit with the new information in the OP:
It sounds as though you actually need to do a number of small string operations here. Since each one individually is quite basic, and I doubt you’d be able to do all those steps (or even a couple of those steps) at one time using a regex, I’d go with the basic functions:
Grab the first half (based on the third location of a substring “000000”) and compare its hash to the next 20 bytes, throwing away anything left.
Use: strpos()
and substr()
Or : /$(.*?0{6}.*?0{6}.*?)0{6}/
Then grab the next 19 bytes after that, and split that into 8 (toss 1) and 8.
Use: substr()
– (I assume you mean 17 bytes here — 8 + 1 + 8)
$part1 = substr($myStr, $currPos, 8);
$part2 = substr($myStr, $currPos + 9, 8);