Re: Newbee: Regular Expressions
| From: | Hans H. Anderson | Date: | Sat, 02 Sep 2000 16:06:07 +0000 |
| Subject: | Re: Newbee: Regular Expressions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14931@lists.php.net to get a copy of this message | ||
Hello Martin,
First off, I highly recommend a book called "Mastering Regular
Expressions" by Jeff Friedl (O'reilly & Associates). It relies heavily on
Perl for examples, but PHP has some Perl-like regex functionality now, so
the book can be very helpful.
Secondly, this:
([0-9]{4})-([0-9]{1,2})
Match any number *at least* four times in a row followed by a dash
followed by at least one number, but no more than two. The () are
groupings, in this case used probably so the author can use those later
(in Perl, those groupings would be in $1 and $2, in PHP it's a little
different (check the docs)).
So, if you had 38479-9, it would match and in Perl $1 would be 38479 and
$2 would be 9.
45-9 or 56789-0987 or 3456-901 would not match.
Hans
On Sat, 2 Sep 2000, Martin Thoma wrote:
> Hello !
>
> I don't know nothing about how to build a regular expression. Could
> someone give me a hint or some examples, what all this
> ([0-9]{4})-([0-9]{1,2})... stuff means ?
Hans Anderson
me@hansanderson.com
http://www.hansanderson.com/
http://www.goofiness.com/