The regular expression: (?i-msx:\.(?:gif|jpg)$) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?i-msx: group, but do not capture (case-insensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- \. '.' ---------------------------------------------------------------------- (?: group, but do not capture: ---------------------------------------------------------------------- gif 'gif' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- jpg 'jpg' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------