01-08-2008, 09:33 PM
|
#1 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
|
Remembering why I hate Regex
Well, I'm trying to do a quick regex match here, and it won't stop choking. The strings are formatted as: - abc
- abc123
- abc123,1
I am trying to skip the initial text, if any, and find that middle number before the comma. Unfortunately it keeps dying. The center number can reach from 1-3 digits in length.
I've tried patterns based off this:
PHP Code:
preg_match('/([\d]{1,3}*?)[,]*/', $hash, $matches);
if(count($matches) === 1) {
if(is_numeric($matches[0][0])) {
$bits = intval($matches[0][0]);
$hex = $bits / 4;
}
}
unset($matches);
However it tells me: "Compilation failed: nothing to repeat at offset 10"
I hope someone around here can remind me how to do it right... 
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
|
|
|
|