m! # Use an alternate delimiter. / # Match a '/' character to anchor off of. ( # Start a capturing parenth. [^/]+ # Match any number of non-'/' characters. \. # Match the '.' character. (?: # Group or constrain without capturing. jpe?g # jpg or jpeg. | gif # or gif | png # or png | tiff? # or tif or tiff ) # End the grouping/constraining parens. \b # Make sure that tiff isn't tiffany, for # example. ) # End the capture. !ix # Case insensitive /i (Ignore the x, it's only # necessary in this expanded example.