我想在 indesign 中使用 GREP 选择括号中的特定文本

问题描述 投票:0回答:1

在以下文字中:

“有 15 只猫(10 黑猫、3 白色猫、2 灰色猫),但其中 4 只失踪了。”

我想选择数字,但只选择括号之间的数字(10、3 和 2)并且只选择数字。不是文字,也不是括号。

我尝试了多种语法,其中一些包括lookbehind和lookahead positif,但我无法找到正确的awnser...

grep adobe-indesign grep-indesign
1个回答
0
投票

尚不清楚您想要获得什么。因此,这里猜测如何使用脚本将字符样式“数字”应用于括号之间的数字:

app.doScript(main, ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT);

function main() {
    var founds = []; // all founds


    // Step 1. Find all texts between brackets

    app.findGrepPreferences = NothingEnum.NOTHING;
    app.findGrepPreferences.findWhat = '\\(.+?\\)';
    var texts_in_brakets = app.activeDocument.findGrep();


    // Step 2. Find numbers inside the all found texts

    while (text = texts_in_brakets.pop()) {
        app.findGrepPreferences.findWhat = '\\d+';
        var nums = text.findGrep();
        while (num = nums.shift()) founds.push(num);
    }


    // Step 3. Apply the character style 'numbers' to the found numbers

    var myStyle = app.activeDocument.characterStyles.item('numbers');
    while (found = founds.pop()) found.applyCharacterStyle(myStyle, true);
}

之前:

之后:

© www.soinside.com 2019 - 2024. All rights reserved.