Re: [PHP] PCRE false match with preg_match?

2005-09-26 Thread Jens Schulze
Murray @ PlanetThoughtful wrote:

> Changing the "*" to a "+" (at least one or more occurrences) could 'fix'
> that pattern (ie so that it doesn't match your string), depending on any
> other values being tested by it.

*keyboardbiting* I see... thanks to all of you who helped so fast.

Jens

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PCRE false match with preg_match?

2005-09-26 Thread Jake Gardner
Murray: I could kick myself for not seeing that one (* = 0 or more,
well it sure found 0)

On 9/26/05, Murray @ PlanetThoughtful <[EMAIL PROTECTED]> wrote:
> > I recently encountered a strange behaviour, could someone please
> > countercheck it, to either tell me there is an error in my pattern?
> >
> > I have a test string: "7005-N/52"
> > I have two match patterns:a) "/([0-9]*)\/(.*)/i"
> >   b) "/([0-9]*)\-(.*)/i"
> > I check the test string with the help of preg_match, and they both
> > matched, but normally variant a) shouldn't have matched.
> >
> > Normally I test my patterns with the tool "The Regex Coach", and
> > according to this tool it shouldn't have matched.
> > PHP version is 5.0.4, PCRE extension version is 4.5 01-December-2003
>
> Hi Jens
>
> Your first pattern 'matches' because it finds a hit on the "/52" component
> of your test string.
>
> If you look at the pattern itself, it's because you're using the
> 'zero-or-more-occurrences' quantifier (ie "*") in the first part of your
> pattern: "([0-9]*)".
>
> It's a valid hit, because there are zero incidences of numeric characters
> immediately prior to the "/52" component of the test string.
>
> Changing the "*" to a "+" (at least one or more occurrences) could 'fix'
> that pattern (ie so that it doesn't match your string), depending on any
> other values being tested by it.
>
> Much warmth,
>
> Murray
> ---
> "Lost in thought..."
> http://www.planetthoughtful.org
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] PCRE false match with preg_match?

2005-09-26 Thread Murray @ PlanetThoughtful
> I recently encountered a strange behaviour, could someone please
> countercheck it, to either tell me there is an error in my pattern?
> 
> I have a test string: "7005-N/52"
> I have two match patterns:a) "/([0-9]*)\/(.*)/i"
>   b) "/([0-9]*)\-(.*)/i"
> I check the test string with the help of preg_match, and they both
> matched, but normally variant a) shouldn't have matched.
> 
> Normally I test my patterns with the tool "The Regex Coach", and
> according to this tool it shouldn't have matched.
> PHP version is 5.0.4, PCRE extension version is 4.5 01-December-2003

Hi Jens

Your first pattern 'matches' because it finds a hit on the "/52" component
of your test string.

If you look at the pattern itself, it's because you're using the
'zero-or-more-occurrences' quantifier (ie "*") in the first part of your
pattern: "([0-9]*)".

It's a valid hit, because there are zero incidences of numeric characters
immediately prior to the "/52" component of the test string.

Changing the "*" to a "+" (at least one or more occurrences) could 'fix'
that pattern (ie so that it doesn't match your string), depending on any
other values being tested by it.

Much warmth,

Murray
---
"Lost in thought..."
http://www.planetthoughtful.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PCRE false match with preg_match?

2005-09-26 Thread Jochem Maas

Jake was fast ;-) and he is on the right track too
(although I don't think that the substrings he guessed are
the exact ones that are found).

you might want to check preg_match_all to see the matches
that PCRE comes up with for each regexp...

also take a look at:

$test = "7005-N/52";
var_dump(
preg_match("/([0-9]*)\/(.*)/i", $test),
preg_match("/([0-9]*)\-(.*)/i", $test),
preg_match("/^([0-9]*)\/(.*)$/i", $test),
preg_match("/^([0-9]*)\-(.*)$/i", $test)
);



Jake Gardner wrote:

When using "/([0-9]*)(.*)/i" it matches
substring 1: 7005
substring 2: -N/52

When using "/([0-9]*)\/(.*)/i" it matches
substring 1:
substring 2: 52

It looks to me as though its trying to match either or subgroup in order.

On 9/26/05, Jens Schulze <[EMAIL PROTECTED]> wrote:


I recently encountered a strange behaviour, could someone please
countercheck it, to either tell me there is an error in my pattern?

I have a test string: "7005-N/52"
I have two match patterns:  a) "/([0-9]*)\/(.*)/i"
  b) "/([0-9]*)\-(.*)/i"
I check the test string with the help of preg_match, and they both
matched, but normally variant a) shouldn't have matched.

Normally I test my patterns with the tool "The Regex Coach", and
according to this tool it shouldn't have matched.
PHP version is 5.0.4, PCRE extension version is 4.5 01-December-2003

Thanks for any help or feedback,
Jens

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php







--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PCRE false match with preg_match?

2005-09-26 Thread Jake Gardner
When using "/([0-9]*)(.*)/i" it matches
substring 1: 7005
substring 2: -N/52

When using "/([0-9]*)\/(.*)/i" it matches
substring 1:
substring 2: 52

It looks to me as though its trying to match either or subgroup in order.

On 9/26/05, Jens Schulze <[EMAIL PROTECTED]> wrote:
> I recently encountered a strange behaviour, could someone please
> countercheck it, to either tell me there is an error in my pattern?
>
> I have a test string: "7005-N/52"
> I have two match patterns:  a) "/([0-9]*)\/(.*)/i"
>b) "/([0-9]*)\-(.*)/i"
> I check the test string with the help of preg_match, and they both
> matched, but normally variant a) shouldn't have matched.
>
> Normally I test my patterns with the tool "The Regex Coach", and
> according to this tool it shouldn't have matched.
> PHP version is 5.0.4, PCRE extension version is 4.5 01-December-2003
>
> Thanks for any help or feedback,
> Jens
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php