how to explain such a regular syntax

how to explain such a regular syntax

am 13.08.2010 08:47:14 von win.acc

Its was picked from drupal source code and i don't know how does it works.
This is the code :
preg_match('/^\[?(?:[a-z0-9-:\]_]+\.?)+$/', $host);

After followed the regular syntax ,i try to cut it into pieces to make
it simpler to
understand ,
part a1: ^\[?
part a2:([a-z0-9-:\]_]+\.?)+$

Then go on cut part a2:
a2_1: ?:
a2_2: ([a-z0-9-:\]_]+\.?)+$
a2_3: a2_2 and +$

a1 means:start with nothing or one "?"
a2_2 means character must be in a-z,0-9 ,"]","_" and the number must
be only one
a2_3 means there must be one and only matched a2_2 string .

And i dint't got a2_1 mean.
Anyone could explain the it works and the fault of my analysis are appreciated!


All you best
------------------------
What we are struggling for ?
The life or the life ?

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

Re: how to explain such a regular syntax

am 13.08.2010 08:51:06 von Peter Lind

On 13 August 2010 08:47, win.a wrote:
> Its was picked from drupal source code and i don't know how does it works.
> This is the code :
> preg_match('/^\[?(?:[a-z0-9-:\]_]+\.?)+$/', $host);

This has got nothing to do with php or php-db - your question is on
regular expressions. Try consulting
http://www.regular-expressions.info/ or get a good book on the topic
like Mastering Regular Expresssions by Jeffrey Friedl.

Regards
Peter

--

WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15


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