Matt
Matt

Reputation: 557

PHP Regex Returning Blank Value when Using Or

My regex returns a blank value when the second value is matched in an OR statement, I want it to ignore the first match if the second one is found

preg_match('/>\s+(?:<input type="submit" value="(.*?)" \/>|<p class="no">(.*?)<\/p>)\s+<\/form>/', $string, $matches);

If first item is matched:

Array
(
    [0] => <input type="submit" value="Go" />
    [1] => Go
)

If second item is matched:

Array
(
    [0] => <p class="no">Value</p>
    [1] => 
    [2] => Value
)

How can I get it to return the second items value in [1] and not [2] ?

Upvotes: 0

Views: 47

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324620

Instead of using (?: to start the options, use (?| [docs]

Upvotes: 3

Related Questions