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

Grep replace goes wrong near endnote reference

Contributor ,
May 05, 2021 May 05, 2021

Hi,

While replacing the close quotes with GREP to one-by-one, its working fine. But useing replace all, the issue happen occuring, the same in coding also (Para breaking). Is this CC2020 bug or any connection with the endnote?

 

app.selection = NothingEnum.NOTHING;

app.findGrepPreferences = app.changeGrepPreferences = null; app.findChangeGrepOptions.includeFootnotes = true;

app.findChangeGrepOptions.includeHiddenLayers = false; app.findChangeGrepOptions.includeLockedLayersForFind = true; app.findChangeGrepOptions.includeLockedStoriesForFind = true; app.findChangeGrepOptions.includeMasterPages = false;

app.findGrepPreferences.findWhat = "(\\[LSQ\\].+?)~]";

app.changeGrepPreferences.changeTo="$1[RSQ]";

myFoundItems =app.documents.item(0).changeGrep();

 

Kindly guide and share if any alternate. Recorded file is attached for your reference. 

 

Thanks,

Selva

TOPICS
Scripting
6.7K
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 1 Correct answer

Guide , May 05, 2021 May 05, 2021

Your Grep syntax is correct and works for me even if I prefer:

 

app.findGrepPreferences.findWhat = "\\[LSQ\\].+?\\K~]";

app.changeGrepPreferences.changeTo = "[RSQ]";

 

(^/)  The Jedi

Translate
Community Expert ,
May 05, 2021 May 05, 2021

What exactly do you mean with 'goes wrong near endnote reference'? Where is the endnote reference and what goes wrong with it?

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
Contributor ,
May 06, 2021 May 06, 2021

Hi Kahrel,

Sorry for the delay,  the below screenshot is useful for better understand. The recorded file is also attached to this blog.

 

Find grep:

Screenshot 2021-05-05 at 11.37.06 AM.png

 Change All:

Screenshot 2021-05-05 at 11.37.44 AM.png

 

Thanks,

Selva

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
Contributor ,
May 06, 2021 May 06, 2021

Attached with this blog.

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 ,
May 06, 2021 May 06, 2021

The problem is that . (the dot) doesn't match the endnote marker.  It should not-match only the paragraph mark. That's an InDesign bug that's been around since CS3 and causes a lot of trouble.

But even if it worked, you can't match some text with an endnote (or a footnote, for that matter, same behaviour), and use it in a variable for a replacement: you just lose the note.

Instead, use this query:

Find what: "\\[LSQ\\][^~]]+\\K~]"

Change to: "[RSQ]"

The [^x] notation means 'not x' and can always be used as an alternative for .+?x

As a bonus, it's more efficient!

P.

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 ,
May 06, 2021 May 06, 2021

"The problem is that . (the dot) doesn't match the endnote marker."

 

Peter, no problem with end notes!

 

(^/)

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 ,
May 06, 2021 May 06, 2021

Crikey, you're right! What do I know about notes, anyway?

Doesn't matter much in this case, but thanks for pointing that out.

P.

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 ,
May 06, 2021 May 06, 2021

As Footnotes can be converted to Endnotes (and Endnotes to Footnotes), it could be simple, if the user has both, to apply a "label" to the right endnotes, convert all to endnotes, play the regex and finally convert the "not-right" endnotes to footnotes! … By Script of course!  😉

 

(^/)

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 ,
May 06, 2021 May 06, 2021

That's flirting with disaster. Endnotes are flakey. Better work around the footnote problem:

 

^.+~F?.*

matches paragraphs with any footnotes.

 

 

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 ,
May 06, 2021 May 06, 2021

Right!  😉

 

So:

 

app.findGrepPreferences.findWhat = "\\[LSQ\\].*~F?.*\\K~]";

app.changeGrepPreferences.changeTo = "[RSQ]";

 

(^/)

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 ,
May 06, 2021 May 06, 2021

Yes, but I'd still use [^~]]+ instead of .*~F?.* because it's more efficient and less messy.

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 ,
May 06, 2021 May 06, 2021

Peter,

 

That doesn't work if there's a foonote in the para!

 

(^/)

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 ,
May 06, 2021 May 06, 2021

Ugh! Back to .*~F.*

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
Contributor ,
May 10, 2021 May 10, 2021

Hi Peter,

Thanks for the suggestion. Yes, most of the grep replacements are not good results. Kindly give the advice to avoid this kind of issue globally. 

 

app.selection = NothingEnum.NOTHING;

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findChangeGrepOptions.includeFootnotes = true;

app.findChangeGrepOptions.includeHiddenLayers = false; app.findChangeGrepOptions.includeLockedLayersForFind = true; app.findChangeGrepOptions.includeLockedStoriesForFind = true; app.findChangeGrepOptions.includeMasterPages = false;

app.findGrepPreferences.findWhat = "["']";

app.changeGrepPreferences.changeTo="[Q1C]";

myFoundItems =app.documents.item(0).changeGrep();

 

 

Before replacement: 

Screen Shot 2021-05-10 at 3.57.06 pm.png

 

After replacement:

Screen Shot 2021-05-10 at 3.57.55 pm.png

 

Thanks,

Selva

 

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 ,
May 10, 2021 May 10, 2021

This is a different problem, please start a new discussion in future.

If you search "["']", how do you find the closing quote and the endnote closing code? If what you show in your screenshot is the result of several queries you should list them all.

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
Contributor ,
May 10, 2021 May 10, 2021

Hi Peter,

Acknowledged, I'll follow this.

 

I'm trying to replace the tag instead of the quote, but the partial tag is misplaced in the next paragraph. 

 

Thanks,

Selva

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 ,
May 10, 2021 May 10, 2021
LATEST

Ah, well, that's an InDesign bug: when you look for ["'] you match the the tag. Not much that you can do about it, other than collecting them all, then processing all found items and replace the first (possible only) character in an item with your text tag.

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 ,
May 05, 2021 May 05, 2021

Your Grep syntax is correct and works for me even if I prefer:

 

app.findGrepPreferences.findWhat = "\\[LSQ\\].+?\\K~]";

app.changeGrepPreferences.changeTo = "[RSQ]";

 

(^/)  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
Contributor ,
May 06, 2021 May 06, 2021

Hi Jedi,

Thanks for this, I'll check and get back you shortly. 

 

 

Thanks,

Selva

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