Reputation: 1054
I have a string that looks like:
Pretext<thecontentineed>
I' trying to write a regex that will pull "thecontentineed" from that string using preg_match
I've tried:
$string = "Pretext<thecontentineed>";
preg_match("/<.*?>/" , $string, $output);
But that returns an empty array.
Upvotes: 1
Views: 821
Reputation: 360702
You haven't specified any capturing groups with ()
:
preg_match('/<(.*)?>/', $string, $matches);
The () instruct the regex pattern to 'capture' whatever matches within the brackets, and store them into the $matches array.
Upvotes: 1
Reputation: 15390
if (preg_match('/Pretext<(.*?)>/', $string, $output)) {
echo $output[1];
}
Upvotes: 0
Reputation: 3020
$string = "Pretext<thecontentineed>";
preg_match("/<(.*?)>/" , $string, $output);
You forgot the ()
Upvotes: 7
Reputation: 60536
$string = "Pretext<thecontentineed>";
preg_match("/\<([^>]+)\>/" , $string, $output);
print_r($output);
Upvotes: 3