Highlighted

apply CharacterStyle jast to "word" without space or dot are before and after "word".

Community Beginner ,
Aug 17, 2020

Copy link to clipboard

Copied


Hi,

I've got a script that searches for content like this and apply CharacterStyle jast to "word" without space or dot or , ...:

word

word.

word,

:word

 

I then do:

 

// ...........................................................................................

var myDoc = app.activeDocument;
var selectedtext = myDoc.selection[0].contents;
var ChStyle = myDoc.selection[0].appliedCharacterStyle.name;
selectedtext = '(?<=\.|،)' + selectedtext + '(?=\.|،)';
app.findGrepPreferences.findWhat = selectedtext;
app.changeGrepPreferences.appliedCharacterStyle = ChStyle;
myDoc.changeGrep();

// ...........................................................................................


I only want to find the contents with the dot.

But this code applied CharacterStyle to all Character of my text ("word.") While I just want to apply to "Word"

Does anyone know why?

 

Thanks,

david

Thanks Manan!
Your suggestion was almost correct and made me find the problem, only the quotes were extra:

This is true:

selectedtext = '(?<=\\.|،)' + selectedtext + '(?=\\.|،)';

TOPICS
Bug, How to, Performance, Publish online, Scripting

Views

78

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

apply CharacterStyle jast to "word" without space or dot are before and after "word".

Community Beginner ,
Aug 17, 2020

Copy link to clipboard

Copied


Hi,

I've got a script that searches for content like this and apply CharacterStyle jast to "word" without space or dot or , ...:

word

word.

word,

:word

 

I then do:

 

// ...........................................................................................

var myDoc = app.activeDocument;
var selectedtext = myDoc.selection[0].contents;
var ChStyle = myDoc.selection[0].appliedCharacterStyle.name;
selectedtext = '(?<=\.|،)' + selectedtext + '(?=\.|،)';
app.findGrepPreferences.findWhat = selectedtext;
app.changeGrepPreferences.appliedCharacterStyle = ChStyle;
myDoc.changeGrep();

// ...........................................................................................


I only want to find the contents with the dot.

But this code applied CharacterStyle to all Character of my text ("word.") While I just want to apply to "Word"

Does anyone know why?

 

Thanks,

david

Thanks Manan!
Your suggestion was almost correct and made me find the problem, only the quotes were extra:

This is true:

selectedtext = '(?<=\\.|،)' + selectedtext + '(?=\\.|،)';

TOPICS
Bug, How to, Performance, Publish online, Scripting

Views

79

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
Aug 17, 2020 0
Adobe Community Professional ,
Aug 17, 2020

Copy link to clipboard

Copied

Try by changing the selectedText to the following

selectedtext = '(?<=\\.|،)' + "selectedtext" + '(?=\\.|،)';

 

Also, you should always reset to null the find/change preferences before and after running the query, i.e., add the following two lines before and after the code snippet you pasted

app.findGrepPreferences = null;

app.changeGrepPreferences = null;

-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...
Aug 17, 2020 1
Community Beginner ,
Aug 17, 2020

Copy link to clipboard

Copied

Thanks Manan!
Your suggestion was almost correct and made me find the problem, only the quotes were extra:

This is true:

selectedtext = '(?<=\\.|،)' + selectedtext + '(?=\\.|،)';

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...
Aug 17, 2020 0
Advocate ,
Aug 30, 2020

Copy link to clipboard

Copied

Variable contents in a lookahead doesn't work!

 

Correct Grep code line:

 

selectedtext = '\\b' + selectedtext + '(?=\\.)';

 

(^/)  The Jedi

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...
Aug 30, 2020 0
Adobe Community Professional ,
Aug 30, 2020

Copy link to clipboard

Copied

Variable contents in a lookahead doesn't work!

It does. In lookbehind it doesn't work.

P.

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...
Aug 30, 2020 1
FRIdNGE LATEST
Advocate ,
Aug 30, 2020

Copy link to clipboard

Copied

Oups! I mean "lookbehind" of course (see my Grep code)!  =D

[Thanks Peter for the comment!]

 

(^/)

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...
Aug 30, 2020 0