Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Using GREP to make conditional line breaks

Return to Member Forum

  • Author
    Posts
    • #64325

      I am working on a lengthy membership directory and would like to find a GREP shortcut for this specific occurance in the directory:

      Our member companies often have “dba” [doing business as] names amended to them. In my InDesign file, some of these names fit on one line in the directory, including the dba name. I want to leave those as they are. However, for longer company names with dba's, two lines are required in the layout. Often, the word “dba” is the last word on the first line, following by the dba name on the second line, like so:

      ABC Company Inc., dba
      XYX Associates

      I would like to find a GREP solution to kick the “dba” down to the second line without having to go through the entire directory and add line breaks manually. But if the whole company name (including the “dba”) fits on one line, I don't want those to break–only where the “dba” creates a second line.

      So in this example, I want to leave it alone:

      DEF Company, dba GHI Inc.

      But in two-line examples like this, I want the “dba” on the second line, like so:

      JKL Company Limited,
      dba MNO Associates

      Reading through other posts, I gather that GREP can't do much with regard manipulating the lines within a paragraph in InDesign, but maybe someone knows of a workaround?

      One that I thought of is to decide on a certain number of characters on a line and then any time the word “dba” is found after that number of characters, insert a line break before it. However, I do not know how to specify that condition in InDesign (i.e., how to input “Find the first 30 characters of any line that has the word 'dba' in it and insert a line break; but if the line doesn't have 30 characters, don't do anything).

      I realize that the solution above is not perfect because I am not using a monospaced font, but still it would probably work for most of the directory, so if someone could supply the GREP for my paragraph above, I would be so grateful.

      Sorry for being so wordy! I've spent hours trying to find a solution online and am frustrated.

      Thanks in advance for any solutions or advice.

    • #64327
      Eugenyus
      Member

      Find what: dba.+(?=$)

      Change To: empty; Change Format: No Break.

    • #64332

      Eugenyus said:

      Find what: dba.+(?=$)

      Change To: empty; Change Format: No Break.


      Eugenyus, thank you VERY much for your help with this! You have saved me several hours of work.

      No pressure, but if you don't mind explaining the commands .+(?=$) so that I know exactly what it is I did, that would be helpful.

      In the meantime, I am determined to better acquaint myself with GREP's potential and am grateful for the resources on this site.

      Thanks again! You ARE a genius!

    • #64333
      Eugenyus
      Member

      Yes, of course)):

      . — any character;

      + — repeat one or more times;

      (?=) — positive lookahead;

      $ — location at the end of paragraph.

Viewing 3 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads