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 + '(?=\\.|،)';
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
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 + '(?=\\.|،)';
Copy link to clipboard
Copied
Variable contents in a lookahead doesn't work!
Correct Grep code line:
selectedtext = '\\b' + selectedtext + '(?=\\.)';
(^/) The Jedi
Copy link to clipboard
Copied
> Variable contents in a lookahead doesn't work!
It does. In lookbehind it doesn't work.
P.
Copy link to clipboard
Copied
Oups! I mean "lookbehind" of course (see my Grep code)! =D
[Thanks Peter for the comment!]
(^/)