Skip to main content
stuart_mccoy
Participant
September 12, 2019
Question

GREP style to catch all hyphenated words

  • September 12, 2019
  • 7 replies
  • 4024 views

I currently use a GREP style, "\w-\w" to catch all hyphenated words such as "4-year" or "end-to-end" but I'm not entirely confident as to how robust it is and where it might fail and catch something unintended. What winds up happening is InDesign catches 4-y" or "d-to-d" and applies my no break style to the text. While this seems to be working fine, I'm about to apply this to a MUCH longer document and I want to make sure I'm not going to encounter any unforeseen issues because this seems too expansive a search for GREP to work with. Does anyone have a snippet they use all the time to handle this sort of thing?

    This topic has been closed for replies.

    7 replies

    Participating Frequently
    January 4, 2024

    I'm not sure if this is any better than your Grep style, but I found this grep style in a video 

    \b\w+?-\w+?\b
    You would just have to make a no break character style and apply it to that. I don't know much about Grep styles, but this worked for me.

    This is the video for more context:
    https://www.youtube.com/watch?v=20WoERcwO2s

    Mike Witherell
    Community Expert
    Community Expert
    May 21, 2023

    <editorial thought in case it helps>

    Sometimes it seems that what you all really want is to turn off hyphenation in the paragraph styles. You can turn this off in select paragraph styles; probably not all of them. Or another approach within paragraph styles is to go into Hyphenation and turn up the requirements for eligibility to hyphenate by setting it to 9, 3, 4, 1, off, off, off (or even numbers higher than 9 letters). Many times the basic problem is that folks are not using paragraph styles to begin with, and so have all these laborious work-arounds they seem to have to contend with. The heart of InDesign is reliance on paragraph styles.

    </editorial thought in case it helps>

    Mike Witherell
    Participant
    May 21, 2023

    The poster's original question wasn't regarding how to eliminate hyphens from the text. It was regarding managing compound phrases autonomously rather than trying to devise complex "work-
    arounds." Turning off hyphens forces Indesign to keep words together rather than line-breaking them and inserting a hyphen. It does nothing for compout phrases that are typed with hyphens such as the words, "work-arounds" and "line-break." 

    Ironicaly, the work around isn't complex at all, the poster just needed to be provided the GREP code to make it happen. Those that don't know, should not be the ones providing solutions.

    Participant
    May 17, 2023

    I came looking for this answer and found it on CreativePro.com by a poster BradWalrod
    "Here are the two GREP styles (applying a “nobreak” character style to both) that I've been using for text paragraphs for a while:

     

    [lu]+(?=[—–-])

     

    (?<=[-–—])[lu]+

     

    (That's a hyphen, en dash, and em dash that it's looking for. I like how you've added the apostrophe, but I wouldn't have gussed that ID would hyphenate before or after one.)

     

    I suppose that instead of your [w|’] and my [-–—], we could consider [S], which would catch anything that's not a space."

    The question was simple, how do you automate the process.  Hope this helps.

     

    Scott Falkner
    Community Expert
    Community Expert
    February 8, 2021

    Why not just apply the GREP style and see what happens? You can use Find/Change to search for the character style and see where it is applied. You can also alter the style to include a highlight colour to make instances easier to spot.

     

    See, even if someone gives you the answer you are looking for, I hope you would check to see that it accoomplished what you want. How do you plan to do that without checking the entire document?

    Participant
    February 8, 2021

    Did you ever get confirmation about this? I use the same style but after Googling there seems to be a lot of more complicated GREP styles which makes me wonder if my simple style is not adequate.

    Participant
    April 22, 2024

    idk if you are still looking friend but I have the answer see above 🙂

     

    Jongware
    Community Expert
    Community Expert
    September 12, 2019

    Why a no-break over hyphens? There is a non-breaking hyphen for that.

    You can use GREP to find-and-replace: search for "(?<=\w)-(?=\w)" and replace with .. uh, the GREP code for a non-breaking hyphen. (Look in the "@' dropdown menu.)

    The advantage is that if it gets applied to something unexpected, you can simply replace that instance with a regular hyphen.

    stuart_mccoy
    Participant
    September 12, 2019
    See above. I would prefer this to be a GREP style I can easily reuse without having to intervene every time the document gets updated or changes are made. This seems to be something well within the wheelhouse of GREP but I'm just a little concerned that my initial attempt ay be too inclusive.
    Participant
    April 22, 2024

    Make a new Character Style> Basic Character>check the box next to "No Break". Name it No Break.

    In your Paragraph Style you want this to apply to, navigate to Grep Style>Apply Character Style>No Break and type in .-. 

    Mike Witherell
    Community Expert
    Community Expert
    September 12, 2019

    Why not test your text with a GREP search first? If that seems fool-proof, allow it to become a GREP style.

    Mike Witherell
    stuart_mccoy
    Participant
    September 12, 2019
    Two reasons. First, I'd love to have a fool-proof go to GREP style to work with whenever I needed it. While it may work on this document, it mat have problem in with future ones and I;d have to retest each time I implemented the style. Second, this is a very long document with a lot of hyphenated footnote markers. It will take tie to go through each instance of the hyphenated words that I'd rather avoid. I was hoping someone may have solved this already and has a snippet they would be willing to share.. I'm trying to learn to use GREP more and more but sometimes I run across something that alludes my limited skills.