Skip to main content
dublove
Legend
June 18, 2026
Answered

How to I include a regular expression in the properties of a paragraph style?

  • June 18, 2026
  • 4 replies
  • 60 views

I want to set some default regular expressions in a paragraph style, for example:

Regular expression: (\d+)
Quote style: myData
Paragraph style: myStyle=app.documents[0]..itemByName(“AA”),
myStyle.properties{

}

Thanks.

    Correct answer Manan Joshi

    Try the following. Make sure the paragraph style with name AA and character style with name myData exists before this code is executed

    var doc = app.documents[0];
    doc.paragraphStyles.itemByName("AA").nestedGrepStyles.add({grepExpression:"\d+[A-Za-Z]", appliedCharacterStyle:doc.characterStyles.itemByName("myData")})

     

    4 replies

    Community Expert
    June 22, 2026

    Hi together,

    here an example where you do not need to do an extra escape of the \d

    var doc = app.documents[0];
    var paraStyle = doc.paragraphStyles.itemByName("AA") ;
    var charStyle = doc.characterStyles.itemByName("myData") ;


    var ns = paraStyle.nestedGrepStyles.add();
    ns.properties =
    {
    // No need to extra escape the expression if you work this way:
    grepExpression : /\d+[A-Za-z]/.source ,
    appliedCharacterStyle : charStyle

    }

    FWIW: the expression \d+[A-Za-Z] with the “a-Z” instead of the “a-z” will give you a syntax error.

     

    Kind Regards,
    Uwe Laubender
    ( Adobe Community Expert )

    dublove
    dubloveAuthor
    Legend
    June 22, 2026

    @Laubender Can't it be directly added to the paragraph style attribute?
    like this:

    paraStyle.properties{

    // No need to extra escape the expression if you work this way:

    grepExpression : /\d+[A-Za-z]/.source ,

    appliedCharacterStyle : charStyle

    }

     

    Manan JoshiCommunity ExpertCorrect answer
    Community Expert
    June 18, 2026

    Try the following. Make sure the paragraph style with name AA and character style with name myData exists before this code is executed

    var doc = app.documents[0];
    doc.paragraphStyles.itemByName("AA").nestedGrepStyles.add({grepExpression:"\d+[A-Za-Z]", appliedCharacterStyle:doc.characterStyles.itemByName("myData")})

     

    -Manan
    dublove
    dubloveAuthor
    Legend
    June 18, 2026

    Hi ​@Manan Joshi 

    Thank you very much.

    Can it be written into the properties
    like this:
    doc.paragraphStyles.itemByName("AA").properties{
    }

    Community Expert
    June 18, 2026
    var doc = app.documents[0];
    var ns = doc.paragraphStyles.itemByName("AA").nestedGrepStyles.add()
    ns.properties = {grepExpression:"\d+[A-Za-Z]", appliedCharacterStyle:doc.characterStyles.itemByName("myData")}

     

    -Manan
    dublove
    dubloveAuthor
    Legend
    June 18, 2026

    Hi ​@Manan Joshi 

    It seems that the expression is incorrect.
    I want to add grep (e.g. \ d+[A-Za-Z]) to the "AA" paragraph style and call the "myData" character style.

    Community Expert
    June 18, 2026

    Which property?

    -Manan