Welcome to the new regex forum.

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

User avatar
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

d11wtq wrote: That's a lookbehind done wrong :P

I guess you meant a lookahead ;)


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.

Code: Select all

function testRegexJokeExpression() {
    // how many regex does it take to change a lightbulb
    // correct answer, any non-zero digit
    $regex = '/\d(?<!0)/';
    //another suggested regex
    $regex = '/\d(?!0)/';
    // this test fails with your regex
    $this->assertFalse(preg_match($regex,'0'), 'fails to fail for case 0');
    //modified this way, it actually would work
    $regex = '/(?!0)\d/';
Last edited by sweatje on Sat Nov 19, 2005 2:36 pm, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

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
User avatar
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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
User avatar
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

that's funny... I just put that on my wish list today. About an hour ago.
Forum Newbie
Posts: 4
Joined: Thu Jun 20, 2013 4:53 am

Re: Welcome to the new regex forum.

Post by ducdm87 »

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
Post Reply