Posted: Sat Nov 19, 2005 11:37 am
Mr Pedantic, looks like you need to brush up on your regex a bitd11wtq wrote: That's a lookbehind done wrong
I guess you meant a lookahead
\d(?!0)
o_O d11wtq is Mr Pedantic for the rest of the day
Code: Select all
function testRegexJokeExpression() {
// how many regex does it take to change a lightbulb
// correct answer, any non-zero digit
$regex = '/\d(?<!0)/';
$this->assertFalse(preg_match($regex,'0'));
$this->assertTrue(preg_match($regex,'1'));
$this->assertTrue(preg_match($regex,'10'));
//another suggested regex
$regex = '/\d(?!0)/';
// this test fails with your regex
$this->assertFalse(preg_match($regex,'0'), 'fails to fail for case 0');
$this->assertTrue(preg_match($regex,'1'));
$this->assertTrue(preg_match($regex,'10'));
//modified this way, it actually would work
$regex = '/(?!0)\d/';
$this->assertFalse(preg_match($regex,'0'));
$this->assertTrue(preg_match($regex,'1'));
$this->assertTrue(preg_match($regex,'10'));
}