in reply to One or more of a pattern...

Your regex has several problems. First, your regex requires at least two instances of foo(num) to match - it can't match just one because the next expressions in the pattern are non-optional.

Also, your regex uses .+? in ways that allow the pattern to defeat your requirements. Consider this string - "foo(10)bar(10)", which I assume shouldn't match. But it will match /.+?\(\d+\)/. The reason is that .+? can match "foo(10)bar" and then the rest of the match can succeed on just "(10)". I fixed this by changing your .+? to [^\(]+ which means "any character except an open paren". You might be able to narrow that down further.

Finally, you didn't anchor your pattern which means that it is free to match anywhere in the string. I added \A to the front and \z to the end to force the regex to span the whole string.

Here's a replacement pattern that works, documented using the /x modifer that allows whitespace and comments:

/ \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;

-sam

UPDATE: My first attempt was bad news. Just goes to show you can never think too carefully about a regex!