Search code examples
regexadobe-indesign

Regex: Match Specific Character in Parentheses


I have the following string:

Character (ccdd)

The c's and d's are necessary for a stupid design reason. I want to highlight c's and d's specifically, so that

a) matches "cc" and b) matches "dd"

with the requirement that it only matches if it is in parentheses.

But I just don't get to it. The only thing I managed so far is:

(?<=\()[c]+?(?=\))

Edit: To further clarify. I need to apply two separate styles to c's and d's in parentheses in InDesign. Therefore I am looking for two separate regex expressions, one that matches all c's in the parentheses and one that matches all d's.

Anyone an idea?

Thank you!


Solution

  • Since the infinite lookbehind and \G are not supported, I suggest using a hack: just checking if the cs or ds are followed with a closing parenthesis.

    Use

    c+(?=[^()]*\))
    

    and 

    d+(?=[^()]*\))
    

    That hack will work if the parentheses are well balanced and if there are no nested parentheses.