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

How to Select all text between two @.

Explorer ,
Dec 20, 2019 Dec 20, 2019

Copy link to clipboard

Copied

Thank you for your help.

Sem Título-2.jpg

TOPICS
Scripting

Views

470

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 2 Correct answers

Community Expert , Dec 20, 2019 Dec 20, 2019

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]*?(?=@)

Votes

Translate

Translate
Advocate , Dec 23, 2019 Dec 23, 2019

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

Votes

Translate

Translate
Community Expert ,
Dec 20, 2019 Dec 20, 2019

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]);
}

 

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
Advocate ,
Dec 20, 2019 Dec 20, 2019

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 

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 ,
Dec 20, 2019 Dec 20, 2019

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]*?(?=@)

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
Advocate ,
Dec 23, 2019 Dec 23, 2019

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

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
Advocate ,
Dec 23, 2019 Dec 23, 2019

Copy link to clipboard

Copied

LATEST

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

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