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

Grep replace goes wrong near endnote reference

Contributor ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

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

Views

2.9K

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

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

Votes

Translate

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

Attached with this blog.

Votes

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

Copy link to clipboard

Copied

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.

Votes

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

Copy link to clipboard

Copied

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

 

Peter, no problem with end notes!

 

(^/)

Votes

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

Copy link to clipboard

Copied

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.

Votes

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

Copy link to clipboard

Copied

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!  😉

 

(^/)

Votes

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

Copy link to clipboard

Copied

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

 

^.+~F?.*

matches paragraphs with any footnotes.

 

 

Votes

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

Copy link to clipboard

Copied

Right!  😉

 

So:

 

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

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

 

(^/)

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

Peter,

 

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

 

(^/)

Votes

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

Copy link to clipboard

Copied

Ugh! Back to .*~F.*

Votes

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

Copy link to clipboard

Copied

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

 

Votes

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

Copy link to clipboard

Copied

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.

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Copy link to clipboard

Copied

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.

Votes

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

Copy link to clipboard

Copied

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

 

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

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

 

(^/)  The Jedi

Votes

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

Copy link to clipboard

Copied

Hi Jedi,

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

 

 

Thanks,

Selva

Votes

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