<?php
 
$html = '
  <a href="http://w...content-available-to-author-only...e.net/index.php?p[some stuff to find]/1/">
  <a href=\'http://w...content-available-to-author-only...e.net/index.php?p[more stuff to find]/1/ \'>
  <a href = http://w...content-available-to-author-only...e.net/index.php?p[unquoted_stuff_to_find]/1/ />
'; 
 
$ref_txtstart = 'http://w...content-available-to-author-only...e.net/index.php?p';
$ref_txtend   = '/1/';
 
$regex =
'~
<a 
  (?=\s) 
  (?= (?:[^>"\']|"[^"]*"|\'[^\']*\')*? (?<=\s) href \s*=
    (?|
        (?>
           \s* ([\'"]) \s*
           ' . preg_quote($ref_txtstart) . ' ((?:(?!\g{-2}).)*) ' . preg_quote($ref_txtend) . '
           \s* \g{-2}
        )
      |
        (?> 
           (?!\s*[\'"]) \s* ()
           ' . preg_quote($ref_txtstart) . ' ([^\s>]*) ' . preg_quote($ref_txtend) . '
           (?=\s|>)
        )
    )
  )
  \s+ (?:".*?"|\'.*?\'|[^>]*?)+ 
>~xs
';
 
echo ("$regex\n");
preg_match_all( $regex, $html, $matches, PREG_SET_ORDER );
foreach ($matches as $val) {
   echo( "matched = $val[0]\ncore    = $val[2]\n\n"  );
}
?>
