The regular expression: (?-imsx:(?:ftp://)?/{5}(a-z_)/) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- (?: group, but do not capture (optional (matching the most amount possible)): ---------------------------------------------------------------------- ftp:// 'ftp://' ---------------------------------------------------------------------- )? end of grouping ---------------------------------------------------------------------- /{5} '/' (5 times) ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- a-z_ 'a-z_' ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- / '/' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------