NYCPHP Meetup

NYPHP.org

[nycphp-talk] quick regex question

David Sklar sklar at sklar.com
Thu Sep 4 10:03:19 EDT 2003


preg_match() always returns the text that matched the entire pattern as the
first element of the $match array. So the only way to have a match array
that contains just the numbers that match your current parenthesized
subpattern is to have an entire pattern that matches just those numbers from
the string. Which I don't think you can do.

Why do you want to do this?

David

> Given:
>
> $swipe = 'A405E,;095612813=1227?2003/08/20 10:51:15 4A4';
>
> preg_match('/\;(.+)\=/s',$swipe,$match);
>
> This fills $match as:
>
> array(2) {
>   [0]=>
>   string(11) ";095612813="
>   [1]=>
>   string(9) "095612813"
> }
>
>
> Can I modify my subpattern somehow, so that only the second
> element of the array is returned?  I don't need the whole string,
> just the matched pattern itself (ie, I don't need the ';' and '='
> chars in the result).
>
> Hopefully I can get my work done and give my take on the
> fundamentals!  Thanks,
>
> H
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk




More information about the talk mailing list