I'm not much of an ereg person, but I'll give it a try.
You could do the ultra simple method of combining them. Put both regexs together in their entirety with a | between them, and surround the whole thing with quotes. Ugly, probably slightly slower, but it should work, and remains true to both regex's.
This is my attempt at combining them. It has a few issues though. It accepts = or ( after any of the terms. It no longer requires a space before href, et al. Probably other issues I forgot. 🙂
eregi("[:space:]*(href|src|background|action|url)[:space:]*[=\\(][:space:]*([^ >\\)]+)", $text, $regs)
As for your second question, I really don't know the necessary ereg, so here's my preg suggestions.
With your particular example you could cheat, since they both start with the same letter, and you only mentioned two alternatives. Just grab the first character from the search and use it in the replacement.
$line = preg_replace("/(h)ello/i", '\\1owdy', $line);
I imagine you want a more general solution though.
$line = preg_replace_callback("/hello/i", 'mycallback', $line);
function mycallback($matches) {
$replacestr = 'howdy';
if ($matches[0]{0} == strtoupper($matches[0]{0})) {
$replacestr{0} = strtoupper($replacestr{0});
}
return $replacestr;
}
Obviously the callback can get a lot more complicated if need be.