Copy link to clipboard
Copied
Thank you for your help.
I thought about a GREP solution too (definitely not my strong suit), but I don't think yours is quite it, Sunil, as it leaves in the @s and catches middle @s. Try this instead for findWhat in Sunil's solution:
(?<=@)[\\s\\S]*?(?=@)
This code would be better :
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "(?<=@)([^@]+)(?=@)";
var allFound = app.documents[0].findGrep();
for(var i = 0; i < allFound.length; i++){
app.select(allFound[i].texts[0]);
}
Best
Sunil
Copy link to clipboard
Copied
I saw your previous question. You could loop through each paragraph like this to apply a paragraph style to each graf.
var pars = app.selection[0].parentStory.paragraphs;
var styleArr = ["paragraphStyle", "paragraphStyle2", etc];
var atCount = 0;
//start at i=1 to skip first @ in first graf
for (var i = 1; i < paragraphs.length; i++) {
//skip styling any @ graf, and up the counter
if (pars[i].contents == "@") {
atCount++;
i++;
}
//style the graf based on array
pars[i].appliedParagraphStyle = app.activeDocument.paragraphStyles.itemByName(styleArr[atCount]);
}
Copy link to clipboard
Copied
Try this code for faster way.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "@[\\s\\S]+@";
var allFound = app.documents[0].findGrep();
for(var i = 0; i < allFound.length; i++){
app.select(allFound[i].texts[0]);
}
Best
Sunil
Copy link to clipboard
Copied
I thought about a GREP solution too (definitely not my strong suit), but I don't think yours is quite it, Sunil, as it leaves in the @s and catches middle @s. Try this instead for findWhat in Sunil's solution:
(?<=@)[\\s\\S]*?(?=@)
Copy link to clipboard
Copied
I am not that good with RegExp, but your RegExp will help lot of people.
That would do the work....
Thanks
Sunil
Copy link to clipboard
Copied
This code would be better :
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "(?<=@)([^@]+)(?=@)";
var allFound = app.documents[0].findGrep();
for(var i = 0; i < allFound.length; i++){
app.select(allFound[i].texts[0]);
}
Best
Sunil