Copy link to clipboard
Copied
Hi All,
I have a question that I am unable to find the answer.
I have an address that is followed by comma after each road name, place and postcode. I would like to have an automated process where the GREP Style will place a soft return or hard return after each comma, regardless if it has more room within the bounding box or not. The reason why I don't want to just place a soft/hard return myself is because the information is driven by a data merge, this information change change drastically depending on the how long the address is.
Please see attached example below.
From:
To:
Thank you,
Scott.
Copy link to clipboard
Copied
GREP Styles can only add styling to text -- you cannot add or remove text with them. You would have to use a GREP search (Find & Change) for this.
Copy link to clipboard
Copied
var myDoc = app.documents[0];
app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren
app.changeGrepPreferences = NothingEnum.nothing; // Ersetzen-Feld leeren
app.findChangeGrepOptions.includeFootnotes = true;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
/*app.findGrepPreferences.appliedParagraphStyle =pStylename; //P style name*/
app.findGrepPreferences.findWhat = "\\,\\s";
app.changeGrepPreferences.changeTo = ",\\r";
myDoc.changeGrep();
app.findGrepPreferences = NothingEnum.nothing; // Suchfeld leeren
app.changeGrepPreferences = NothingEnum.nothing;
Copy link to clipboard
Copied
SJRiegel​ is correct, GREP styles cannot change the spaces to either a soft or a hard return. But this might work – emphasis on the "might" because it is, quite literally, quite a stretch.
The character style "no-break" only sets No Break. This is necessary because otherwise InDesign will try to break between all of the words, rather than just on the spaces after the comma.
The character style "wiiiideeeeee" sets 1000% Horizontal Scale and Tracking: +1000.
Here comes the trick: you cannot see it in this screenshot (and I'm about to go home for today so I won't shoot it again), but after the top "To Text: (?<=,)" there is a single space at the end. And that is the space that you see in the screenshot at the right, all stretched out.
(It won't work if your frame is so wide that even the thousands' of scaling and tracking does not suffice.)