regex &align:%HORIZONTAL%|%VERTICAL%

I would like to have a regex that matches something like this:

&align:%HORIZONTAL%|%VERTICAL%

%HORIZONTAL% may be "left" or "right" or "center"

%VERTICAL% may be "top" or "bottom" or "center"

I tried something like this:

&align:(left|right|center)\|(top|bottom|center)

And I got this:

Array(
[0] => &align:left|center
[1] => left
[2] => top
)

What would I have to change to get only one match at all? The [1] and [2] must not be possible.

Answers


Parentheses serve two purposes — grouping and capturing. To get the grouping you want without capturing the matches, use ?::

&align:(?:left|right|center)\|(?:top|bottom|center)

Manual reference: http://uk3.php.net/manual/en/regexp.reference.subpatterns.php


Need Your Help

Assign Event Programmatically to Child Inside FormView

c# asp.net event-handling formview

I realize you can declaratively assign an event handler to a child control inside a formview by adding its attribute on the aspx page (i.e. onclick="Button_Click"), but if I wanted to do this

How do I develop against OAuth locally?

python oauth

I'm building a Python application that needs to communicate with an OAuth service provider. The SP requires me to specify a callback URL. Specifying localhost obviously won't work. I'm unable t...