Search code examples
regexstubby4j

How can I match some part of request body?


I am capturing request in stubby4j like this

-  request:
      method: POST
      url: /someUrl
      post: ".*(amit).*"

It works fine if I use single line in request body. E.g. User name is amit gupta. But it fails if I use multiline text as

User name is amit gupta 
secondline

How can I match some part of request body?


Solution

  • Judging by the documentation, you just can use

    "[\\s\\S]*(amit)[\\s\\S]*"
    

    The [\s\S] construct matches any character that is either whitespace (\s) or non-whitespace (\S). Note that the parentheses around amit only make sense if you use the backreference to it later, thus, I'd remove these brackets.