Highlighted

Find a phrase which maybe broken up by hard or soft return in several spots

Community Beginner ,
May 11, 2020

Copy link to clipboard

Copied

I am creating an auto translate for some flyers i can search and replace as GREP but I cannot seem to get to work in my indesign script

In GREP if i search 

'(?i)selection(\v*|\h*)varies(\v*|\h*)by(\v*|\h*)store'

I can find the instances but if I put the same thing into a script which is working for other find and replaces it does not find the phrase.

any guidance would be most helpful

JJ

 

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

Hi JJ,

 

I think you must have not escaped your grep expression properly. Seems to be working for me just fine on a test document. Try the following code and let me know if it works or not. This is alert the no of occurrences found of the text

 

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '(?i)selection(\\v*|\\h*)varies(\\v*|\\h*)by(\\v*|\\h*)store';
var a = app.documents[0].findGrep()
alert(a.length)
app.findGrepPreferences = null;

 

P.S. While asking a query please do give relevant information, like what is the test data you are searching against and what is code you wrote. Just saying its not working makes it difficult to provide proper feedback

 

-Manan

TOPICS
How to, Scripting

Views

338

Likes

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

Find a phrase which maybe broken up by hard or soft return in several spots

Community Beginner ,
May 11, 2020

Copy link to clipboard

Copied

I am creating an auto translate for some flyers i can search and replace as GREP but I cannot seem to get to work in my indesign script

In GREP if i search 

'(?i)selection(\v*|\h*)varies(\v*|\h*)by(\v*|\h*)store'

I can find the instances but if I put the same thing into a script which is working for other find and replaces it does not find the phrase.

any guidance would be most helpful

JJ

 

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

Hi JJ,

 

I think you must have not escaped your grep expression properly. Seems to be working for me just fine on a test document. Try the following code and let me know if it works or not. This is alert the no of occurrences found of the text

 

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '(?i)selection(\\v*|\\h*)varies(\\v*|\\h*)by(\\v*|\\h*)store';
var a = app.documents[0].findGrep()
alert(a.length)
app.findGrepPreferences = null;

 

P.S. While asking a query please do give relevant information, like what is the test data you are searching against and what is code you wrote. Just saying its not working makes it difficult to provide proper feedback

 

-Manan

TOPICS
How to, Scripting

Views

339

Likes

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
May 11, 2020 0
Adobe Community Professional ,
May 11, 2020

Copy link to clipboard

Copied

Hi JJ,

 

I think you must have not escaped your grep expression properly. Seems to be working for me just fine on a test document. Try the following code and let me know if it works or not. This is alert the no of occurrences found of the text

 

app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = '(?i)selection(\\v*|\\h*)varies(\\v*|\\h*)by(\\v*|\\h*)store';
var a = app.documents[0].findGrep()
alert(a.length)
app.findGrepPreferences = null;

 

P.S. While asking a query please do give relevant information, like what is the test data you are searching against and what is code you wrote. Just saying its not working makes it difficult to provide proper feedback

 

-Manan

Likes

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
Reply
Loading...
May 11, 2020 2
Advocate ,
May 11, 2020

Copy link to clipboard

Copied

In Javascript you need to double the escape character you find in some metacharacter. 

So \v will be \\v, etc.

Likes

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
Reply
Loading...
May 11, 2020 1
Adobe Community Professional ,
May 12, 2020

Copy link to clipboard

Copied

Hi JJ_Cloutier,

see my answer how to debug a GREP expression for findWhat in this reply to you for a similar question:

https://community.adobe.com/t5/indesign/how-to-use-appliedconditions-in-a-indesign-script/m-p/111247...

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
May 12, 2020 1