Skip navigation
Currently Being Moderated

GREP style question

Jan 8, 2013 1:42 PM

Looking for a GREP style to find text within parenthesis and including the parenthesis, but only if text contains a hyphen. Here is an example: through out the copy there will be pronunciations i.e. Diagnostic (die-ag-NOS-tik) which I want to find this situation and apply a character style, but not the following: Intravenous (IV). TIA

 
Replies
  • Currently Being Moderated
    Jan 8, 2013 2:09 PM   in reply to Jeffrey_Smith

    On my way out the door, but see if this works for you. I did a small test, and it seems to, but I haven't tried all the variables.

     

    (\()([\l\u]+(-))+([\l\u]+)(\))

     

    Here's the What the Grep breakdown:

     

    (\()([\l\u]+(-))+([\l\u]+)(\))

     

    (     Begin Group #1

        \(     Literal opening parenthesis

    )     End Group #1

    (     Begin Group #2

        [     Inclusion: any character in this group

            \l     Any lowercase character (a..z)

            \u     Any uppercase character (A..Z)

        ]     End Inclusion Group

        +     Any character in this group may occur once or more times; longest possible match will be taken

        (     Begin Group #3

            -     Literal character “-”

        )     End Group #3

    )     End Group #2

    +     The entire Group #2 may occur once or more times; longest possible match will be taken

    (     Begin Group #4

        [     Inclusion: any character in this group

            \l     Any lowercase character (a..z)

            \u     Any uppercase character (A..Z)

        ]     End Inclusion Group

        +     Any character in this group may occur once or more times; longest possible match will be taken

    )     End Group #4

    (     Begin Group #5

        \)     Literal closing parenthesis

    )     End Group #5

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 8, 2013 5:47 PM   in reply to SRiegel

    Based on the description of any text with a hyphen between parentheses that seems overly complex to me. I'd use

     

    \(.+?-.+?\)

     

    that's the openin parenthesis, any text up to a hypehen (shorest match), the hyphen itself, any additional text up to a close parenthesis (shortest match) and the close parenthesis itself. This will match more than a single word in a string between parentheses if at least one contains a hyphen.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points