• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

GREP : Replace empty spaces

Community Beginner ,
Sep 13, 2017 Sep 13, 2017

Copy link to clipboard

Copied

Hi !

I've been working on this all day and have been able to find only half an answer so I come here full of hope… ! 😃

I have a table which I import from Excel. In this table I have empty cells sometimes and I want to put a "-" in them.

I tried this grep request to find the empty spaces : (?<!.)$

Which seems to work, it finds empty spaces in the format I searching when I press "Next"

I tried to "replace" the empty spaces using : $0-

Which, oddly enough, works when I press "Replace" but doesn't when I press "Replace all"

Here is my problem then, how can I make it work all at once ? Since I don't want to replace them all at once… ^^''

Thanks in advance !

Views

888

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Sep 13, 2017 Sep 13, 2017

It ought to be as easy as Find: $ and Change to: - ... but it's not.

You may find interesting this thread. Don't bother with the answer marked as 'correct', look for Jongware's posts 6 and maybe 14.

Didn't try it myself, though.

Likes

Translate

Translate
Mentor ,
Sep 13, 2017 Sep 13, 2017

Copy link to clipboard

Copied

It ought to be as easy as Find: $ and Change to: - ... but it's not.

You may find interesting this thread. Don't bother with the answer marked as 'correct', look for Jongware's posts 6 and maybe 14.

Didn't try it myself, though.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 14, 2017 Sep 14, 2017

Copy link to clipboard

Copied

Hi

This is an interesting puzzler.

Like winterm said before, you probably need a script to achieve this.
I haven't tested Jongware's script either, but I'm sure it would do the job...

Although, I would like to share a few thoughts :

  • In Excel, you can easily write and run a macro to replace empty-cell by a dash. Something like this:

For Each cel In Range("A1:Z200") //Don't forget to adjust your Range

  If IsEmpty(cel.Value) Then cel.Value = "-"

Next


        So, if you use linked file, it could be an acceptable solution.

  • If you use a very simple table, with no merging, no funny stuff and that you just use a table style, you can also convert table to text, run a Grep query to look for 2 consecutive column separators, separator at the beginning and at the end of a paragraph. Finally revert text to table and apply your table style.
    This is quite a brutal workaround, and you should be very cautious with it... (I wonder if I should have shared this crazy thought ^^)

  • I was very curious and surprised you said that your Grep query did allow you to "Replace" (even only once)...
    Since nothing is selected, how could "Replace" work?
    So I tested your GREP query, and... it didn't work for me... (Windows 7 - Indd CS6)
    But... copying a dash into the pasteboard and replacing by ~C did work somehow, and still surprisingly... with the same limitation than you though: "Replace All" does not work (Obviously !).
    However Find/Replace button did the job and if you don't have thousands of empty cells, it can be an acceptable workaround.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Sep 14, 2017 Sep 14, 2017

Copy link to clipboard

Copied

Point 1. Macros in Excel still aren't my friends, couldn't comment.

Point 2. I must confess I also considered (silently) this trick, but found it too drastic and didn't dare to share... Hey man, you're the brutal beast!

Point 3. Ha! Again, we think alike! Also played this all (incl. clipboard contents), and got identical results. So could only confirm here.

Jongware's script is the way to go, imo.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 14, 2017 Sep 14, 2017

Copy link to clipboard

Copied

Theun is right here!

Place the cursor in any cell! Short version:

var a = app.selection[0].parent.parent, b = a.cells,  c = b.length;

while (c--) if (b.contents.length == 0) b.contents = "-";

(^/) 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 14, 2017 Sep 14, 2017

Copy link to clipboard

Copied

  1. They can be so handy combined with INDD
  2. Glad I'm not the only one with a twisted mind
  3. see point 2

Jongware's script is the way to go, imo.

Well, that's definitely true!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

Use "^$" without the Quotes.

Note: If you hit the "Find Next" button it will say it cannot find a match. Hit the "Change All" and it will work. At least it does for me.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

FWIW:

With the current versions of InDesign, e.g. InDesign 2021 and 2022 the following will work:

GREP Find pattern:

^\Z

GREP Change:

-

 

No issue to find the first instance, then do change and find next.

No need to do Change All.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

A warning:

GREP will not recognize the special character that makes a Table object!

 

So, if you do a Change All the pattern "Find the beginning of a story, its first text insertion point, or the beginning of a table's text cell, the first insertion point in that cell, followed by the end of the story or the end of the text of a table cell" will also find the insertion point after that table and add a - after the table that is positioned in an otherwise empty text frame.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

Running the latest version of InDesign and this (^\Z) only works with the Change All button for me, just the same as using match End of Line ($).

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

Are you on Mac or Windows?

I tested with InDesign 17.3.0 on Windows 10.

 

Could you post a sample InDesign document where you see the issue?

 

EDITED:
Attached my test document:

GREP-FindEmptyStories-2022.indd

 

GREP-ChangeFindNext.PNG

 

Regards,
Uwe Laubender
( Adobe Community Professional )

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

Mac Big Sur 11.6.8

InDesign 17.3

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

Thanks @TheAngryPorge ,

well, I also have some issues with your document looking for empty cells.

 

But this changed as soon as I switched the scope of the search from Document to Selection when I selected some of the table rows. Strange indeed…

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

Indeed, it does seem to work with the scope changed to story or selection, but only when I had an insertion point in a cell and not with just the table selected. Just for giggles I tried ^$ using both scopes and it worked as well if having the insertion in the table.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

LATEST

Also had this:

Had my Find scope set on Document.

Pressed the button for Find.

Message was: Nothing found.

 

Next I clicked Change All and over 1245 instances were reported found and changed.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines