FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » too many matches regex
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: too many matches regex [message #176663 is a reply to message #176661] Mon, 16 January 2012 08:08 Go to previous messageGo to previous message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma:
Senior Member
.oO(cate)

> $s = '1 2 20 - 31 55 56 77 - 88 97 - 99';
>
> $patRange = '/((\d+) *- *(\d+))/';
>
> $matches = array();
> preg_match_all($patRange, $s, $matches);
>
> I expected to see an array with 3 matches for each of the there number
> "ranges" found in the
> string $s (20 - 31, 20 and 31).... I see 4. Why? Need some insight
> from a jones. I don't understand what I'm seeing.

The results of the preg_match_* functions always contain a full pattern
match at the [0] index. The matches from the parentheses then start at
index [1]. Since you've parenthesized the entire pattern, you'll see
that result twice.

Micha

--
http://mfesser.de/blickwinkel
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: php with openssl in static mode (binaries for windows)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 16:41:28 GMT 2024

Total time taken to generate the page: 0.04084 seconds