Skip to main content
Fightergator
Inspiring
Sep 27, 2025 12:06 AM UTC
Answered

Questions Regarding Assertions & Capture Group ExtendScript Support

I recall a couple of earlier posts regarding ES support for assertions; specifically, that while ES supports lookahead assertions, it does not support lookbehind assertions.  In my experience, while the Find/Change panel appears to support both, and I've successfully used positive lookbehinds in the FrameMaker 2022 scripts, negative lookbehinds do not appear to work in ES.  Can anyone confirm this and/or point me to a more definitive discussion regarding ES support for assertions.  I use these extensively to search documents for capitalization, hyphenation, spacing, and spelling errors that are outside the scope of the dictionary.

 

My other question is regarding capture groups.  While capture groups seem to work OK in the Find/Change panel, I've run into problems using them in scripts.  Maybe I'm doing something wrong.  Any suggestions welcome.  

    frameexpert
    frameexpertCorrect answer
    Community Expert
    Sep 27, 2025 4:40 PM UTC

    ExtendScript is based on an older version of JavaScript and does not support lookbehinds in its regular expressions. FrameMaker's Find/Change regular expressions use Perl as a default, which does support lookbehinds. I have sucessfully used captured groups with ExtendScript.

    www.frameexpert.com

    4 replies

    frameexpert
    Community Expert
    frameexpertCommunity ExpertCorrect answer
    Community Expert
    Sep 27, 2025 4:40 PM UTC

    ExtendScript is based on an older version of JavaScript and does not support lookbehinds in its regular expressions. FrameMaker's Find/Change regular expressions use Perl as a default, which does support lookbehinds. I have sucessfully used captured groups with ExtendScript.

    Translate
    www.frameexpert.com
    Fightergator
    Inspiring
    Sep 27, 2025 10:33 PM UTC

    Rick...thanks for getting back to me.  I've spend most of the day experimenting with capture groups (I'll work on lookbehind assertions next week).  I've had some success with the following function:

    var find = apple pie;
    var replaceString = $2 $1 // change = pie apple
    function captureGroups(find) {
        var parts = find.split(/[ -]/);
        var regex = /^(\w+)[ -](\w+)$/;   // Regex to create capture groups
        change = find.replace(regex, replaceString);
        return change;
        }

    It handles two capture groups and I can probably adjust the function for 3 or more capture groups (but would have to do it manually).  Optional captures for the first capture group (or prefix) e.g., 
    find = '\b(?:apple|blueberry)[- ](pie)'; replace = 'banana $2'; work just fine.  

     

    However, when I try to use optional captures for the second capture group, it doesn't work; e.g.,

    find = '\b(apple)[- ](pie|tart|cobbler)  or (?:pie|tart|cobbler), replace = $1$2;  // remove the space or hyphen

    finds apple pie, apple tart, and apple cobbler, and changes them to applepie, applepie, and applepie regardless of the second word. 

     

    I'd like to use options in my capture groups for both first capture group and second if that's possible.  Any ideas?

    Translate
    frameexpert
    Community Expert
    Community Expert
    Sep 29, 2025 12:12 PM UTC

    I can look at this more later, but your first two lines should be quoted strings.

    var find = "apple pie";
    var replaceString = "$2 $1" // change = pie apple
    Translate
    www.frameexpert.com