/^ # Match the start of the string a # Single occurrence of the character a (.+) # Grab one or more other characters # and put into $1 [fg] # a single character, either "f" or "g" $ # match the end of the string /x # x modifier to allow comments in regex