Question: Here's the regex I'm working with. It works fine, but now I'm trying to get the results.

Basically, if the name/property/etc contains "title" I want it to echo the contents of the title meta tag.

In other words, I want the corresponding out[2], not out[1], when out[1] contains "title" (case insensitive).

```
  $pattern = '
  ~<\s*meta\s

  # using lookahead to capture type to $1
    (?=[^>]*?
    \b(?:name|property|http-equiv)\s*=\s*
    (?|"\s*([^"]*?)\s*"|\'\s*([^\']*?)\s*\'|
    ([^"\'>]*?)(?=\s*/?\s*>|\s\w+\s*=))
  )

  # capture content to $2
  [^>]*?\bcontent\s*=\s*
    (?|"\s*([^"]*?)\s*"|\'\s*([^\']*?)\s*\'|
    ([^"\'>]*?)(?=\s*/?\s*>|\s\w+\s*=))
  [^>]*>

  ~ix';

if(preg_match_all($pattern, $link_html, $out))
{
    foreach ($out[1] as $out)
    {
        echo $out.'<br>';
    }   
}

```

Answer: 
You asked for a Regex but using an HTML Parser and XPath would be so much easier and more readable:

```
<?php

$html = <<< HTML
<html>
    <head>
        <meta name="author" lang="en" content="Gordon" />
        <meta name="title" lang="en" content="match this" />
        <meta property="title" lang="en" content="and this" />
        <meta http-equiv="title" lang="en" content="and also this" />
        <meta foo="title" content="but not this" />
    </head>
    <body>Use DOMDocument for HTML parsing instead</body>
</html>
HTML;

libxml_use_internal_errors(true);
$dom = new DOMDocument;
$dom->loadHTML($html);
libxml_use_internal_errors(false);

$xpath = new DOMXPath($dom);
$nodes = $xpath->evaluate(
    '//meta[
       @*[
         contains("name|property|http-equiv", name())
         and contains(., "title")
         ]
       ]/@content'
);

foreach ($nodes as $node) {
    echo $node->nodeValue, PHP_EOL;
}

```

Output:

```
match this
and this
and also this

```

The XPath means *find all content attributes of any meta tags where any of the attribute names is part of the string "name|property|http-equiv" and which contains the value "title"* in that attribute.

As you can hopefully see, the XPath itself almost reads as if it was natural language (as opposed to the regex you used).
That should be possible by capturing the array index in the `foreach` loop, like this:

```
foreach ($out[1] as $index => $out) {
    if(stristr($out, 'title')) echo $out[2][$index].'<br>';
}

```