Skip to main content
Known Participant
February 12, 2025
Answered

grep not find a table in a paragraph

  • February 12, 2025
  • 9 replies
  • 954 views

Hi grep and script experts;

I want to select all paragraphs that start with a number and end with "END". But I can't select all of them because there is a table in the paragraph. Can you help me?

 

Correct answer FRIdNGE

As you can see in the Grep F/R [french] window, I use the Grep Code provided by the op [I've just added a "?" to make the Found more precise, but the op's code remains correct]. My Script is based on this Grep F/R with finally 4 Found!

 

 

(^/)

 

 

9 replies

Peter Spier
Community Expert
Community Expert
February 12, 2025

Aside from potential bugs, your screen shot shows that there are no paragraphs that actually start with a digit and end with END.  There are 4 distinct paragraphs in that story: The first is empty, the second starts with 15 and ends at the hyphen before the table, the third contains only the table, and the fourth ends with the word END, but starts with Velis, not a number.

That might not be the only reason the GREP fails to find a match, but there ceertainly is none to find here.

FRIdNGE
FRIdNGECorrect answer
February 12, 2025

As you can see in the Grep F/R [french] window, I use the Grep Code provided by the op [I've just added a "?" to make the Found more precise, but the op's code remains correct]. My Script is based on this Grep F/R with finally 4 Found!

 

 

(^/)

 

 

uniq1Author
Known Participant
February 12, 2025

Hi FridNGE;

I want to give a single paragraph style to all paragraphs. Including the text inside the table. I also want to give a condition to all text. Grep doesn't work for me but it seems to work for you...

FRIdNGE
February 12, 2025

Why do you want to select these texts? [to make what…]

 

(^/)  The Jedi

Peter Kahrel
Community Expert
Community Expert
February 12, 2025

This is a known problem: the dot doesn't match the table character (U+0017). The dot doesn't match the footnote marker either, but at least there's a workarounf for that. That workaround doesn't work for tables though. The problem is that even a GREP search for the table character (look for \x17 or \x{0017}) won't find anything. (In the Text tab you can look for <0017>, which does find tables.)

 

The only way I know of to deal with this is to find all ^\d, then find all END\r, and process the text between these start and end points. Along these lines:

 

app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = '^\\d';
starts = app.activeDocument.findGrep();

app.findGrepPreferences.findWhat = 'END\\r';
ends = app.activeDocument.findGrep();

if (starts.length !== ends.length) {
  // Log a problem
  exit();
}

for (i = starts.length-1; i >= 0; i--) {
  fragment = starts[i].parentStory.characters.itemByRange (
    starts[i].index, ends[i].index+4
  );
  // Now do something with the fragment
  process (fragment); // To be defined
}
uniq1Author
Known Participant
February 12, 2025

Thank you @Peter Kahrel 

I have confirmed that the grep code is not working. I will have to continue with the script.