Skip to main content
Fightergator
Inspiring
September 27, 2025
Answered

Questions Regarding Assertions & Capture Group ExtendScript Support

  • September 27, 2025
  • 1 reply
  • 181 views

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.  

    Correct answer frameexpert

    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.

    1 reply

    frameexpert
    Community Expert
    frameexpertCommunity ExpertCorrect answer
    Community Expert
    September 27, 2025

    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.

    Fightergator
    Inspiring
    September 27, 2025

    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?

    frameexpert
    Community Expert
    Community Expert
    September 29, 2025

    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