Regex in Dataverse Search

In order to find the correct Dataverse record in App Service or any other application we often use Web API web service to perform HTTP requests with filters. But what is the filter value contains additional symbols? For example, mobile numbers can look like “+<country code><number>” or “+(<country code>)<number>” or contain additional spaces between digits.

The Dataverse search can handle it. Be sure that all needed set-up for the search is ready (entities and attributes are available for the search).

The Dataverse search syntax is next:

POST [Organization URI]/api/search/v1.0/query
{  
  "search": "<search term>"
}

Other parameters are optional. For example, you can specify entities where you are searching for:

POST [Organization URI]/api/search/v1.0/query
{  
  "search": "<search term>",
  "entities": ["<entity1>","<entity2>"]
}

For Regex, it is important to specify the search type parameter with the “full” value:

POST [Organization URI]/api/search/v1.0/query
{  
  "search": "<search term>",
  "searchtype": "full",
  "entities": ["<entity1>","<entity2>"]
}

Because the default value is “simple”, but “full” search type supports Regex:

In “search” you should specify the regular expression for searching:

{
    "searchtype":"full",
    "search":"/.*3[-. ]*4[-. ]*5[-. ]*6[-. ]*7[-. ]*8[-. ]*9[-. ]*/",
    "entities":["contact"]
}

Below is an example of searching the contacts with the phone number +38 012 345 67 89.

There are two contacts with the same mobile phone, but written in different formats:

+380123456789

+38 012 345 67 89

The HTTP request and response are:

The same result you would see when using the global search: