javascriptregexmountebank

Java script regex to accept multiple values including empty in Mountebank predicates


I was trying to accept multiple values including empty in Mountebank predicates.

As per below in the query parameter I want to accept both false and empty value.

Tried below and it doesn't accept neither isValid=false nor isValid=

"predicates":[
   {
      "matches":{
         "method":"GET",
         "path":"/accounts",
         "query":{
            "isValid":"/false|^null$/"
         }
      }
   }
],
"responses":[
   {
      "....."
   }
]

I tried below option as well as per this

"isValid":"/false.^null$|^null$.false/"

Solution

  • You need to use

    "matches": {
        "data": "^(?:false)?$" 
    }
    

    Here,