Jump to content
KAZOOcon: hackathon signup and details here! ×

Setting Multiple Regex Pattern Matches on an Offnet/Resource Document in Couch


extremerotary

Recommended Posts

A question was posed about how to set an offnet resource to match more than one regex pattern match in the rules[ ] array.

There are 2 methods to achieve this behavior. Both (as far as I know) are acceptable, and vary only in readability. When viewing a carrier document in the offnet database in couch, you'll notice there is an array element for "rules". In the world of regular expressions, capture groups are separated by a pipe "|". So if you're looking for one regular expression to match more than one string, you can use the method listed below. In my example, I want this carrier to match a specific number in Italy, and also any calls to the Netherlands, country code 31. In order to match, the number must be exactly "+390805345208", OR +31 followed by at least 9 digits. 

"rules": [
       "^\\+(390805345208)$|^\\+((31)\\d{9,})$"
   ]

Looking above, this may be hard for some people to read, so it can also be written as 2 individual expressions because the rules element is an array:

"rules": [
       "^\\+(390805345208)$",
       "^\\+((31)\\d{9,})$"
   ]

Link to comment
Share on other sites

×
×
  • Create New...