title: Trie search with regex: C++
body: <p>Ok I have to search a Trie tree with input like "*all", where * could be any character. I know that using a regex_match to match a search for a string, like with the other trees, where you're searching a whole word. But since the search algorithm for a Trie goes by characters I am having trouble converting the regular search algorithm to my needs.</p>
  
  <p>Here is the untouched, regular code for a trie search without the *</p>
  
  <pre><code> bool Trie::searchWord(string s){
  Node* cur = root;
  
  while(cur != NULL){
      for(int i = 0; i &lt; s.length(); i++){
          Node* tmp = cur-&gt;findChild(s[i]);
          if(tmp == NULL){
              return false;
          }//end if
          cur = tmp;
      }//end for
      if(cur-&gt;wordMarker()){
          return true;
      }else{
          return false;
      }//end if-else
  }//end while
  return false;
  }//end searchWord(s)
  
  Node* Node::findChild(char c){
  for(int i = 0; i&lt;mChildren.size(); i++){
      Node* tmp = mChildren.at(i);
      if(tmp-&gt;content() == c){
          return tmp;
      }//end if
  }//end for
  return NULL;
  }//end findChild(c)
  </code></pre>
  
  <p>Here is my attempt to modify it. It works for regular words still but doesn't work for the *</p>
  
  <pre><code>bool Trie::searchWordRegex(string s){
  Node* cur = root;
  
  while(cur != NULL){
      regex reg ;
      for(int i = 0; i &lt; s.length(); i++){
          if(s[i] == '*'){
              reg = regex("(\\w)");
          }//end if
          Node* tmp = cur-&gt;findChildRegex(s[i], reg);
          if(tmp == NULL){
              return false;
          }//end if
          cur = tmp;
      }//end for
      if(cur-&gt;wordMarker()){
          return true;
      }else{
          return false;
      }//end if-else
  }//end while
  return false;
  }//end searchWord(s)
  
  Node* Node::findChildRegex(char c, regex r){
  for(int i = 0; i&lt;mChildren.size(); i++){
      Node* tmp = mChildren.at(i);
      string s(1,tmp-&gt;content());
      if(tmp-&gt;content() == c || regex_match(s, r)){
          return tmp;
      }//end if
  }//end for
  return NULL;
  }//end findChild(c)
  </code></pre>
  
  <p>Is there a way I can fix these functions to work? Or is there as easy way like with the regex_match for the other trees?</p>
  
  <p>Thank you. </p>