2017-06-20 91 views
0

的Javascript grep的最后一场比赛,我这里InDesign中的文本:InDesign中:在一个段落

Hello (World), 
this (nonsense) text 
nobody (needs, right?). 

随着我的JSX脚本我想选择用括号(needs, right?)最后一场比赛。 但是这个结果是用常规和斜体格式化的(needs是斜体,其余的是常规的)。但我只想改变常规风格。

在我的剧本的部分看起来像这样:

function myFindGrep(myObject, mySearchString, mySearchStyle, myStyleGroup, myStyle){ 
    app.changeGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences.findWhat = mySearchString; 
    app.findGrepPreferences.fontStyle = mySearchStyle; 
    app.changeGrepPreferences.appliedCharacterStyle = myDocument.characterStyleGroups.item(myStyleGroup).characterStyles.item(myStyle); 
    var myFoundItems = myObject.changeGrep(); 
    app.changeGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences = NothingEnum.nothing; 
} 

myFindGrep(selText.paragraphs.item(x), "\(.+?\)", "Regular", "Meist genutzte", "Zitat Regular"); 

当我申请这一点,改变我的选择孔除了斜体字...

是有办法解决这一问题?

+0

你的脚本似乎做什么我可以观察的工作。 – Loic

回答

0

我不得不修改我的职责,做了第二次的grep:

function myFindQuote(myObject, mySearchString, mySearchStyle, myStyleGroup, myStyle) { 
    app.changeGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences = NothingEnum.nothing; 
    app.findGrepPreferences.findWhat = mySearchString; 
    var myFoundItems = myObject.findGrep(); 

    for (var i = 0; i < myFoundItems.length; i++) { 
     app.changeGrepPreferences = NothingEnum.nothing; 
     app.findGrepPreferences = NothingEnum.nothing; 
     app.findGrepPreferences.fontStyle = mySearchStyle; 
     app.changeGrepPreferences.appliedCharacterStyle = myDocument.characterStyleGroups.item(myStyleGroup).characterStyles.item(myStyle); 
     myFoundItems[i].changeGrep(); 
    } 
}