title: Regex match hyphenated word with hyphen-less query
body: <p>I have an Azure Storage Table set up that possesses lots of values containing hyphens, apostrophes, and other bits of punctuation that the Azure Indexers don't like. <code>Hyphenated-Word</code> gets broken into two tokens — <code>Hyphenated</code> and <code>Word</code> — upon indexing. Accordingly, this means that searching for <code>HyphenatedWord</code> will not yield any results, regardless of any wildcard or fuzzy matching characters. That said, Azure Cognitive Search possesses support for Regex Lucene queries...</p>
  <p>As such, I'm trying to find out if there's a Regex pattern I can use to match words with or without hyphens to a given query. As an example, the query <code>homework</code> should match the results <code>homework</code> <em>and</em> <code>home-work</code>.</p>
  <p>I know that if I were trying to do the opposite — match unhyphenated words even when a hyphen is provided in the query — I would use something like <code>/home(-)?work/</code>. However, I'm not sure what the inverse looks like — if such a thing exists.</p>
  <p>Is there a raw Regex pattern that will perform the kind of matching I'm proposing? Or am I SOL?</p>
  <p><strong>Edit</strong>: I should point out that the example I provided is unrealistic because I won't always know where a hyphen <em>should</em> be. Optimally, the pattern that performs this matching would be agnostic to the precise placement of a hyphen.</p>
  <p><strong>Edit 2</strong>: A solution I've discovered that <em>works</em> but isn't exactly <em>optimal</em> (and, though I have no way to prove this, probably isn't <em>performant</em>) is to just break down the query, remove all of the special characters that cause token breaks, and then dynamically build a regex query that has an optional match in between every character in the query. Using the <code>homework</code> example, the pattern would look something like <code>[-'\.! ]?h[-'\.! ]?o[-'\.! ]?m[-'\.! ]?e[-'\.! ]?w[-'\.! ]?o[-'\.! ]?r[-'\.! ]?k[-'\.! ]?</code>...which is perhaps the ugliest thing I've ever seen. Nevertheless, it gets the job done.</p>