Skip to main content
Participant
September 27, 2022
Answered

GREP change in a single column of table.

  • September 27, 2022
  • 2 replies
  • 309 views

I need help with GREP. What I have is a very large table with several columns. One of the columns I need to change a specfic 4 to a 1 in all instances. Example, 123-4567-894. I only want to change the ending 4 to a 1. The 4 I need changed is always the last 4 of the numerical string and only that 4.

Thank you

This topic has been closed for replies.
Correct answer Peter Spier

While I'm sure Peter K's script will do what you want (as long as you have at least two didgits at the end of the number), he did leave ourt an option that is available in the Find/Change dialog: Selection.

You could just select the entire column and look for 4$ and it would find all 4s that end a paragraph in that column.

2 replies

Participant
September 28, 2022

Thank you both so much! The 4$ worked like a dream! Thank you again!

Peter Kahrel
Community Expert
Community Expert
September 27, 2022

InDesign's Find/Change interface offers only four scopes for finding and replacing (the familiar all documents, document, story, and to end of story), but in a script you can constrain a find-and-replace action to many more things.

 

To replace something in a table column, place the cursor in the column, then do

app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = '\\d\\K4$';
app.changeGrepPreferences.changeTo = '1';
app.selection[0].parent.parentColumn.changeGrep();

\d\K4$ stands for 'a (\d) digit when followed (\K) by 4 at the end of the line/paragraph ($)'.

Peter Spier
Community Expert
Peter SpierCommunity ExpertCorrect answer
Community Expert
September 27, 2022

While I'm sure Peter K's script will do what you want (as long as you have at least two didgits at the end of the number), he did leave ourt an option that is available in the Find/Change dialog: Selection.

You could just select the entire column and look for 4$ and it would find all 4s that end a paragraph in that column.

Peter Kahrel
Community Expert
Community Expert
September 28, 2022

Selection -- of course! Thanks for that, Peter S.