Skip to main content
dublove
Legend
Jun 18, 2026 7:10 AM UTC
Answered

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

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.

    Manan JoshiCorrect answer
    Community Expert
    Jun 18, 2026 10:37 AM UTC

    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

    9 replies

    Community Expert
    Jun 22, 2026 12:54 PM UTC

    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 )

    Translate
    dublove
    dubloveAuthor
    Legend
    Jun 22, 2026 2:32 PM UTC

    ​@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

    }

     

    Translate
    Manan JoshiCommunity ExpertCorrect answer
    Community Expert
    Jun 18, 2026 10:37 AM UTC

    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")})

     

    Translate
    -Manan
    dublove
    dubloveAuthor
    Legend
    Jun 18, 2026 11:05 AM UTC

    Hi ​@Manan Joshi 

    Thank you very much.

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

    Translate
    Community Expert
    Jun 18, 2026 11:21 AM UTC
    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")}

     

    Translate
    -Manan
    dublove
    dubloveAuthor
    Legend
    Jun 18, 2026 9:28 AM UTC

    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.

    Translate
    Community Expert
    Jun 18, 2026 7:21 AM UTC

    Which property?

    Translate
    -Manan