PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Jul 22, 2017 9:43 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Sat Nov 19, 2005 12:37 pm 
Offline
Forum Contributor
User avatar

Joined: Wed Jun 29, 2005 10:04 pm
Posts: 277
Location: Iowa, USA
d11wtq wrote:
That's a lookbehind done wrong :P

I guess you meant a lookahead ;)

\d(?!0)

o_O d11wtq is Mr Pedantic for the rest of the day :P


Mr Pedantic, looks like you need to brush up on your regex a bit ;) Here is a simpletest test case.

Syntax: [ Download ] [ Hide ]
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'));
 
}
 


Last edited by sweatje on Sat Nov 19, 2005 3:36 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 19, 2005 3:33 pm 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia
Ah I see what you meant lol.... the tests made it clearer :)

I though you meant any number of regex less than ten (i.e. 1-9) ... I hadn't considered you were looking for a number not starting with a zero.

*shy's away* 8O


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 9:27 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
This is a good a place as any to drop a resource. I don't know if anyone noticed, but O'Reilly released a new edition of Mastering Regular Expressions. This version includes a bunch of pages on PHP apparently.

Here's the link supplied by "the manual:" http://www.amazon.com/exec/obidos/ASIN/ ... /wwwphpnet


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 10:35 pm 
Offline
The Ninja Space Mod
User avatar

Joined: Fri Aug 05, 2005 1:53 pm
Posts: 6424
Location: Paradise, CA
that's funny... I just put that on my wish list today. About an hour ago.


Top
 Profile  
 
PostPosted: Thu Jun 20, 2013 4:58 am 
Offline
Forum Newbie

Joined: Thu Jun 20, 2013 4:53 am
Posts: 4
i see http://www.regular-expressions.info/tutorial.html is good tutorial
What sites do you know good online regex test. I see http://php.toolregex.com use good, easy to use interface


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group