/^ #Match at the beginning of the string ( #begin $1 [a-zA-Z_)[3,] #A character class .* #Any number of characters ? #Minimal match the .* ) #End $1 : #Match a colon ( #Begin $2 .* #Match until end of line )/x #End $2 and the match