Reply to Re: Regular Expression: How the rule is applied for the Pattern '/((red|white) (king|queen))/'

Your name:

Reply:


Posted by Rik Wasmus on 01/22/08 15:03

On Tue, 22 Jan 2008 15:41:34 +0100, mosesdinakaran@gmail.com =

<mosesdinakaran@gmail.com> wrote:
> Hi Thanks for the reply,

Thank me by not top-posting :).

> Can you please tell me what I have under stood is right?
>
> After the start of capture no.2 the pattern starts with the word
> r is matched with t (the red king) -> NO Match
> r is matched with h -> No Match
> r is matched with e -> No Match
> .
> .
> .
> r is matched with r -> Match Found
> Now the engine moves to the Next character in the pattern ie e
> re is matched with re -> Match Found
> red is matched with red -> Match Found
>
> Since we have a | it comes out from the #first capture and now we
> have an empty
> space
>
> red(space) is matched with red(space)
> red(space)k is matched with red(space)k
> .
> .
> red(space)king is matched with red(space)king -> Match Found
>
> Now the value is returned and we get the first match
>
> array
> (
> [0] =3D> the red king
> )
>
> Is the above mentioned procedure is correct?

Not exactly how it happens 'under water', but as far as the outcome, yes=
, =

that's correct. I take it the internals of the regex engine are not the =
=

concern, but the use of regular expressions themselves?

> Also I was not able to find out how the other three values
>
> Array
> (
> [1] =3D> red king
> [2] =3D> red
> [3] =3D> king
> )

Euhm, I even numbered the captures for you in my previous post... Suffic=
e =

to see every subpattern between () gets its own entry in the match array=
, =

unless you specifiy an uncaptured subpattern (?:
-- =

Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация