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

481 views Asked by At

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/"
1

There are 1 answers

2
Wiktor Stribiżew On BEST ANSWER

You need to use

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

Here,

  • ^ - matches start of string
  • (?:false)? - an optional (due to ? at the end) non-capturing group that matches a char sequence false one or zero times
  • $ - end of string.