title: How to do regular expression search using lucene.Net
body: <p>I m using lucene.Net version 3.0.3. I want to do regular expression search. I tried the following code:</p>
  
  <pre><code>// code
  
  String SearchExpression = "[DM]ouglas";
  
  const int hitsLimit = 1000000;
  
  //state the file location of the index
  string indexFileLocation          = IndexLocation;
  Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.Open(indexFileLocation);
  
  //create an index searcher that will perform the search
  Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(dir);
  
  var analyzer = new WhitespaceAnalyzer();
  
  var parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, new[] {                 
              Field_Content, }, analyzer);
  
  Term t = new Term(Field_Content, SearchExpression);
  RegexQuery scriptQuery = new RegexQuery(t);
  
  string s = string.Format("{0}", SearchExpression);
  
  var query = parser.Parse(s);
  
  BooleanQuery booleanQuery = new BooleanQuery();
  booleanQuery.Add(query, Occur.MUST);
  
  var hits = searcher.Search(booleanQuery, null, hitsLimit, Sort.RELEVANCE).ScoreDocs;
  
  
  foreach (var hit in hits)
  {
      var hitDocument = searcher.Doc(hit.Doc);
  
      string contentValue = hitDocument.Get(Field_Content);
  }
  
  // end of code
  </code></pre>
  
  <p>When I try to search with patten <code>"Do*uglas"</code>, I get the results. </p>
  
  <p>But if I search with the pattern <code>"[DM]ouglas]"</code> it is giving me the following error: </p>
  
  <pre><code>"Cannot parse '[DM]ouglas': Encountered " "]" "] "" at line 1, column 3. Was expecting one of: "TO" ... &lt;RANGEIN_QUOTED&gt; ... &lt;RANGEIN_GOOP&gt; ...".
  </code></pre>
  
  <p>I also tried doing simple search pattern like <code>".ouglas"</code> which should give me results, as I have <code>"Douglas"</code> in my text content.</p>
  
  <p>Does anyone know how to do regular expression search using lucene.Net version 3.0.3?</p>