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

GREP works in the InDesign UI but not in script

Engaged ,
Jun 08, 2017 Jun 08, 2017

Copy link to clipboard

Copied

Hi,

I've got a script that searches for content like this:

section 10.1

section 9

I put this content into a variable called matchContent.

I then do:

matchContent.match ( "(?<!\\d\\.)\\d+(?!\\d?\\.)" );

I only want to find the contents with the dot.

But this only works in the UI. In the script it never finds the digit.

Does anyone know why?

Thanks,

Jake

TOPICS
Scripting

Views

1.1K

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

People's Champ , Jun 08, 2017 Jun 08, 2017

HI jake,

I thought you were trying to use negative lookbehind/ahead in pure ExtendScript which I never get to work (is it an ExtendScript limitation ?) Let me rephrase, I mean using a regular expression on a pure string object.

Now I understand you want to do F/C through Scripting. Well, it seems like you have it all or close.

app.findGrepPreferences=app.changeGrepPreferences=null;

app.findGrepPreferences.findWhat = "(?<!\\d\\.)\\d+(?!\\d?\\.)";

should be ok for setting grep options.

Now finding tex

...

Votes

Translate

Translate
Engaged ,
Jun 08, 2017 Jun 08, 2017

Copy link to clipboard

Copied

I've just tried findGrep() as well which is even more weird.

app.findGrepPreferences=app.changeGrepPreferences=null;

    app.findGrepPreferences.findWhat = "(?<!\\d\\.)\\d+(?!\\d?\\.)";  

  

    var sectionNumber = match.findGrep(),

If I alert section number it gives me an [object Character] or [object Word].

However if I access a property on it, it's undefined...

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
Engaged ,
Jun 08, 2017 Jun 08, 2017

Copy link to clipboard

Copied

At this point match is an [object TextStyleRange]

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
People's Champ ,
Jun 08, 2017 Jun 08, 2017

Copy link to clipboard

Copied

HI jake,

I thought you were trying to use negative lookbehind/ahead in pure ExtendScript which I never get to work (is it an ExtendScript limitation ?) Let me rephrase, I mean using a regular expression on a pure string object.

Now I understand you want to do F/C through Scripting. Well, it seems like you have it all or close.

app.findGrepPreferences=app.changeGrepPreferences=null;

app.findGrepPreferences.findWhat = "(?<!\\d\\.)\\d+(?!\\d?\\.)";

should be ok for setting grep options.

Now finding text. You need to execute the findGrep on some text based object (or the doc or app objects). That could be a story, a paragraph, a word, etc.

var found = myStory.findGrep();

Which will return an array of results. Each array Item references the text object that matches the expression.

alert( found[0].contents ); //given that the result are not empty.

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
Engaged ,
Jun 08, 2017 Jun 08, 2017

Copy link to clipboard

Copied

LATEST

Hi Loic,

Thank you for the great answer!

I've finally got it working

It probably needs a polish but if your interested I can post it here?

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