How do you match one of two words in a regular expression?

Try:

/(@|at)/

This means either @ or at but not both. It's also captured in a group, so you can later access the exact match through a backreference if you want to.


/(?:@|at)/

mmyers' answer will perform a paren capture; mine won't. Which you should use depends on whether you want the paren capture.


if that's only 2 things you want to capture, no need regex

if ( strpos($string,"@")!==FALSE || strpos($string,"at") !==FALSE ) {
  # do your thing
}