/ \A # start at the beginning of the string [^\(]+ # match one or more non-( characters \(\d+\) # match a (number) expression ( # start the optional part : # a single, required colon [^\(]+ # match one or more non-( characters \(\d+\) # match a (number) expression )* # match this subexpression zero or more times \z # end at the end of the string /x;