0

Consider the following set:

2017.16, 2017.16.a, 2017.16.b, 2017.167

I am trying to use a regular expression to search my azure index and return: 2017.16.a, 2017.16.b

using the following as my query:

accession_number:/2017\.16\.*/

returns three documents: 2017.16, 2017.16.a, 2017.16.b

How can I change the regular expression to only include the .a and .b records?

Ryan
  • 45
  • 5

1 Answers1

1

Assuming this field is not "searchable", you're getting this match because the end of the regex ("16.*") matches anything that ends in 16 followed by zero or more (including multiple) periods. If you want to only include exactly "a" or "b" as suffixes, you could use:

/2017\.16\.(a|b)/

If you want to allow exactly 1 more character, any character:

/2017\.16\../
Pablo Castro
  • 1,644
  • 11
  • 11
  • I escaped the "\."(period), I want to find everything that begins with the string "2017.16." including the final period. "2017.16" doesn't have the final period and "2017.167" wouldn't match either. but there could be any number of matches (not just a and b, those are just simple examples) and not just one more character, but 1 or more characters (ex 2017.16.aaaa 2017.16.cd). I had problems using ^ or /A for a starts with search, and other things I tried with Azure Search. – Ryan Jul 08 '19 at 19:13
  • The period is escaped, but after that you had "*", which means zero or more of whatever was before. This causes the regex to match the case ending in ".16" (no period). If you want anything that starts with "2017.16." (including the period), you'll need to use a variation of the second example I provided above: /2017\.16\..*/ Note that it has a escaped period (to match an actual period), and then ".*" to match any suffix. – Pablo Castro Jul 10 '19 at 23:20
  • 1
    /2017\.16\..*/ was what I needed, and had tried, but wasn't working. I needed to add Analyzer = AnalyzerName.Keyword to the definition of the field. Once that was added, the above regex worked like a charm. It seems the field was being tokenized causing problems with my regex attempts. – Ryan Jul 12 '19 at 13:09