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

Reg ex scripting

Explorer ,
Sep 30, 2021 Sep 30, 2021

Copy link to clipboard

Copied

Hi everyone, im trying to format a line of text that has a bullet separator. see example below.

 

before: Word • Word Word Word

convert to: Word • Word Word Word

 

However, it only formats the first word after the bullet. I want to convert all the succeding words to condensed like the example above.

 

heres the code im currently using;

app.findGrepPreferences.properties = ({findWhat:"\\• \\w+"});
app.changeGrepPreferences.properties = ({fontStyle:"Condensed"});
 
thank you!
TOPICS
Scripting

Views

163

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 Expert , Sep 30, 2021 Sep 30, 2021

Hi Joseph,

 

Have a look at this script:

 

var doc = app.activeDocument,

// the regex to find anything before first bullet
// uses a 'positive lookahead' ?=
myFindWhat = '^.*?(?=•)',

// this is example change to make
changeStyle = doc.characterStyles.itemByName("Bolder");

if (!changeStyle.isValid) {
    alert('There is no character style named "Bolder".');
    return;
}

// set up the find/changes
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.
...

Votes

Translate

Translate
Community Expert ,
Sep 30, 2021 Sep 30, 2021

Copy link to clipboard

Copied

Hi Joseph,

 

Have a look at this script:

 

var doc = app.activeDocument,

// the regex to find anything before first bullet
// uses a 'positive lookahead' ?=
myFindWhat = '^.*?(?=•)',

// this is example change to make
changeStyle = doc.characterStyles.itemByName("Bolder");

if (!changeStyle.isValid) {
    alert('There is no character style named "Bolder".');
    return;
}

// set up the find/changes
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = myFindWhat;
app.changeGrepPreferences.appliedCharacterStyle = changeStyle;

// do the changes
doc.stories.everyItem().paragraphs.everyItem().changeGrep();

 

 

But do you know you can do this exact thing using a Grep Style?

Screen Shot 2021-10-01 at 9.22.06 am.png

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
Explorer ,
Sep 30, 2021 Sep 30, 2021

Copy link to clipboard

Copied

Hi @m1b thank you for the code you've provided. How about for lines that have multiple bullets?

example: Word • Word • Word • Word • Word

convert to: Word • Word • Word • Word • Word

 

Thank you!

 

We are also using the Grep Style, however I need to include some scripting that is not availble on Greps.

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
Explorer ,
Sep 30, 2021 Sep 30, 2021

Copy link to clipboard

Copied

@m1b please disregard my second inquiry, I've figured it out base on the code you gave! Thank you so much!

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 ,
Oct 01, 2021 Oct 01, 2021

Copy link to clipboard

Copied

LATEST

Great! Glad you figured it out! And you're right, my regex finds characters before every bullet, not just the first. Oops, didn't test. I've edited my original.

- Mark

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