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

grep not find a table in a paragraph

Participant ,
Feb 11, 2025 Feb 11, 2025

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?

 

s1.jpg

TOPICS
Scripting
970
Translate
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 2 Correct answers

Community Expert , Feb 11, 2025 Feb 11, 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 te

...
Translate
Guide , Feb 12, 2025 Feb 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!

 

TableNote.gif

 

(^/)

 

 

Translate
Community Expert ,
Feb 11, 2025 Feb 11, 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
}
Translate
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
Participant ,
Feb 12, 2025 Feb 12, 2025

Thank you @Peter Kahrel 

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

Translate
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 ,
Feb 12, 2025 Feb 12, 2025

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

 

(^/)  The Jedi

Translate
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 ,
Feb 12, 2025 Feb 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.

Translate
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 ,
Feb 12, 2025 Feb 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!

 

TableNote.gif

 

(^/)

 

 

Translate
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
Participant ,
Feb 12, 2025 Feb 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...

Translate
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 ,
Feb 15, 2025 Feb 15, 2025

@uniq1 

 

Because Search strings are different:

 

RobertatIDTasker_0-1739665324136.png

 

RobertatIDTasker_2-1739665390056.png

 

There is extra "?" before "END".

 

Translate
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
Participant ,
Feb 16, 2025 Feb 16, 2025

Hi @Robert at ID-Tasker r

I know but it doesn't work that way either...

Translate
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 ,
Feb 17, 2025 Feb 17, 2025
LATEST
quote

Hi @Robert at ID-Tasker r

I know but it doesn't work that way either...


By @uniq1

 

For me neither...

 

@FRIdNGE 

 

What your script is doing exactly?

Can you post its contents?

 

Translate
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