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 #176665 is a reply to message #176661] Mon, 16 January 2012 08:30 Go to previous message
Curtis Dyer is currently offline  Curtis Dyer
Messages: 34
Registered: January 2011
Karma:
Member
cate <catebekensail(at)yahoo(dot)com> wrote:

> $s = '1 2 20 - 31 55 56 77 - 88 97 - 99';
>
> $patRange = '/((\d+) *- *(\d+))/';

Remove the outermost parentheses. See below.

> $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.
>
> Thank you.

In the matches returned, you have to account for the overall match
against the pattern itself. In this case, the outermost subpattern
is superfluous, since it yields the same result as the overall
match.

<snip print_r() output of the matches>

--
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>
[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 18:34:24 GMT 2024

Total time taken to generate the page: 0.04254 seconds