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

Apply character style to whole word which contains a letter

Community Beginner ,
Jun 10, 2024 Jun 10, 2024

Copy link to clipboard

Copied

Hello.

 

I have a long list of words (one word per line) like so:

"Pothole 

Painting 

Comb

School 

Tent

Ring"

 

I want to apply character style to all the words that contain letters "n", and extract those words to a new indesign file.

 

Please help.

Thanks and regards. 

TOPICS
Scripting

Views

166

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 , Jun 10, 2024 Jun 10, 2024

Does this Grep helps you?

[\l\u]*[nN]+[\l\u]*

 

Votes

Translate

Translate
Community Expert , Jun 10, 2024 Jun 10, 2024

For exporting the matched words to a file you can use the following script

 

var doc = app.documents[0]
app.findGrepPreferences.findWhat = "[\\l\\u]*[nN]+[\\l\\u]*"
var f = doc.findGrep()
app.findGrepPreferences.findWhat = NothingEnum.NOTHING
var s = ""
for(var i = 0; i < f.length; i++){
    s += f[i].contents + "\n"
}
if(s != ""){
    var f = new File("~/Desktop/out.txt")
    f.open("w")
    f.write(s)
    f.close()
}

 

I could not make your regex work so I used @pixxxelschubser's regex. You ca

...

Votes

Translate

Translate
Community Expert ,
Jun 10, 2024 Jun 10, 2024

Copy link to clipboard

Copied

Does this Grep helps you?

[\l\u]*[nN]+[\l\u]*

 

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 ,
Jun 10, 2024 Jun 10, 2024

Copy link to clipboard

Copied

Thanks for the reply.

[\w]*[nN]+[\]*

this grep pattern worked for me.

 

Kindly help with the extraction of all matching words to a new file as well.

I can guess that this involves some kind of script.

Thanks.

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 ,
Jun 10, 2024 Jun 10, 2024

Copy link to clipboard

Copied

LATEST

For exporting the matched words to a file you can use the following script

 

var doc = app.documents[0]
app.findGrepPreferences.findWhat = "[\\l\\u]*[nN]+[\\l\\u]*"
var f = doc.findGrep()
app.findGrepPreferences.findWhat = NothingEnum.NOTHING
var s = ""
for(var i = 0; i < f.length; i++){
    s += f[i].contents + "\n"
}
if(s != ""){
    var f = new File("~/Desktop/out.txt")
    f.open("w")
    f.write(s)
    f.close()
}

 

I could not make your regex work so I used @pixxxelschubser's regex. You can change the regex to what you want in the code in line no. 2, just make sure you escape \. The script will create a file names out.txt on the desktop

-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