Skip to main content
nickm74821483
Participating Frequently
March 11, 2018
Answered

Finding/Replacing Beginning or End of a Line

  • March 11, 2018
  • 2 replies
  • 4463 views

Does anyone know how to find the beginning or end of a line in InDesign (NOT the beginning or end of a paragraph, and NOT a forced line break) and replace it with a forced line break or a paragraph break.

Here's my situation:

I have many, many irregular text frames with 5,000+ names in one long paragraph. The complete names are separated by bullets. The complete names are held together by nonbreaking spaces, and the bullets have spaces before them to that the lines can wrap.

What I need to do is identify any bullet that comes at the beginning of a line (wrapped automatically) and replace that with a forced line break.

Example

I need to go from this (using the text character symbols):

Jane^sSmith •^sJJohn^sSmith •^sKarl^sSmith

•^sLarry^sSmith •^sMike^sSmith •^sNed^sSmith

•^sOlive^sSmith •^sPaul^sSmith •^sRob^sSmith

To this:

Jane^sSmith •^sJJohn^sSmith •^sKarl^sSmith^n

Larry^sSmith •^sMike^sSmith •^sNed^sSmith^n

Olive^sSmith •^sPaul^sSmith •^sRob^sSmith^n

I can't find a GREP solution or a Text find/replace solution. Only thing I can figure out is to do it by hand. Any great ideas out there?

    This topic has been closed for replies.
    Correct answer FRIdNGE

    Hi,

    Even if it's simple to do it here with Grep:

    One single para! … So include 2 temporary nested line styles [[none] char styles called "X" and "Y"] to isolate each line and run 2 regex as:

    1/

    Find: (?<!.)~8~s

    Replace by: \n

    Find format: "X"

    2/

    Find: (?<!.)~8~s

    Replace by: \n

    Find format: "Y"

    … I prefer these 2 [JS] code lines! … Just place the cursor in the para and run them!

    var myLines = app.selection[0].paragraphs[0].lines.everyItem().getElements(),  L = myLines.length;

    while (L--) if ( myLines.characters.itemByRange(0,1).contents == "• " ) myLines.characters.itemByRange(0,1).contents = "\n";

    Using "para line" Javascript feature! … So, simply search the two first chars of each line and replace them by a soft-return if they are: "• "

    Best,

    Michel, from FRIdNGE

    2 replies

    FRIdNGE
    FRIdNGECorrect answer
    March 12, 2018

    Hi,

    Even if it's simple to do it here with Grep:

    One single para! … So include 2 temporary nested line styles [[none] char styles called "X" and "Y"] to isolate each line and run 2 regex as:

    1/

    Find: (?<!.)~8~s

    Replace by: \n

    Find format: "X"

    2/

    Find: (?<!.)~8~s

    Replace by: \n

    Find format: "Y"

    … I prefer these 2 [JS] code lines! … Just place the cursor in the para and run them!

    var myLines = app.selection[0].paragraphs[0].lines.everyItem().getElements(),  L = myLines.length;

    while (L--) if ( myLines.characters.itemByRange(0,1).contents == "• " ) myLines.characters.itemByRange(0,1).contents = "\n";

    Using "para line" Javascript feature! … So, simply search the two first chars of each line and replace them by a soft-return if they are: "• "

    Best,

    Michel, from FRIdNGE

    Participating Frequently
    March 13, 2018

    Nice one!

    It doesn't work until I saved the script in UTF-8.

    Thanks!

    winterm
    Legend
    March 11, 2018

    Unfortunately, there’s no specific GREP code for 'end of line' in InDesign layout.

    FWIW, exporting to pdf has this side effect (usually unwanted) of adding hard returns at the end of every line…