Need quick regex help with matching the same word twice

I need some quick regex help with matching the same word twice in a pattern.

For example, I'm trying to match on the PHP code: if (isset($foo) AND $foo) or if (isset($bar) AND $bar) where $foo and $bar are any valid variable name. However, I don't want to match on if (isset($foo) AND $bar).

Can anyone help me with this? Thanks!!