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

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

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

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

Views

265

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

Community Beginner , Aug 17, 2020 Aug 17, 2020

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

This is true:

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

Votes

Translate

Translate
Community Expert ,
Aug 17, 2020 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

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 Beginner ,
Aug 17, 2020 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 + '(?=\\.|،)';

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

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

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

Copy link to clipboard

Copied

LATEST

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

[Thanks Peter for the comment!]

 

(^/)

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