Forum Discussion

joanna's avatar
joanna
New Contributor
7 years ago

Is it possible to use regex pattern as a input parameter in a POST method?

Can we use regex pattern as an input value of a parameter in POST method?

  • Lucian's avatar
    Lucian
    Community Hero
    I don't fully understand. What are you trying to achieve? Usually you use regex for assertions. I don't get how you would be able to use it as input.
    • richie's avatar
      richie
      Community Hero

      Hi joanna

       

      I've never tried it myself but just an additional comment to Lucian's.

       

      If you consider the syntax you use in a regex pattern - specifically the reserved chars in a regex pattern that can ALSO occur in an input parm - e.g. curly braces, normal bracket characters and $ character - unless you have a way to escape these (and I don't mean html encoding sort of escape - cos I've tried this previously and that doesn't work for input parms) then I don't see how you would achieve this.

       

      There's probably further implications that I haven't considered - but thats the big one that jumps out at me

       

      Sorry I couldn't be of more help,

       

      Cheers,

       

      richie

  • aaronpliu's avatar
    aaronpliu
    Frequent Contributor

    it's possible. But not sure what your requirement is.

    if you wanna input parameter with code in payload of POST, then you would use like below

    // assume that a value is true or false according to your input
    // assume 'a123' is your dynamical input below
    // below value will be true
    ${=java.util.regex.Pattern.matches('(a|b)[0-9]+','a123')}

    Hopefully it is an example for you to figure out what you required.

     

     

    Thanks,

    Aaron

  • aaronpliu's avatar
    aaronpliu
    Frequent Contributor

    it's possible. But not sure what your requirement is.

    if you wanna input parameter with code in payload of POST, then you would use like below

     

    // assume that a value is true or false according to your input
    // assume 'a123' is your dynamical input below
    // below value will be true
    ${=java.util.regex.Pattern.matches('(a|b)[0-9]+','a123')}

     

    Hopefully it is an example for you to figure out what you required.

     

     

    Thanks,

    Aaron