简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM