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
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
...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...
Copy link to clipboard
Copied
At this point match is an [object TextStyleRange]
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.
Copy link to clipboard
Copied
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?