In PHP how do I complete a regex that returns only what was grouped
Posted
by maestrojed
on Stack Overflow
See other posts from Stack Overflow
or by maestrojed
Published on 2010-05-15T00:42:23Z
Indexed on
2010/05/15
0:44 UTC
Read the original article
Hit count: 556
I want to perform a regex using grouping. I am only interested in the grouping, its all I want returned. Is this possible?
$haystack = '<a href="/foo.php">Go To Foo</a>';
$needle = '/href="(.*)">/';
preg_match($needle,$haystack,$matches);
print_r($matches);
//Outputs
//Array ( [0] => href="/foo.php"> [1] => /foo.php )
//I want:
//Array ( [0] => /foo.php )
© Stack Overflow or respective owner