title: Java regex to match the start of the word?
body: <p><strong>Objective</strong>: for a given term, I want to check if that term exist at the start of the word. For example if the term is 't'. then in the sentance:</p>
  
  <blockquote>
    <p>"This is the difficult one Thats it"</p>
  </blockquote>
  
  <p>I want it to return "<strong>true</strong>" because of : </p>
  
  <blockquote>
    <p>This, the, Thats</p>
  </blockquote>
  
  <p>so consider:</p>
  
  <pre><code>public class HelloWorld{
  
   public static void main(String []args){
  
      String term = "t";
      String regex = "/\\b"+term+"[^\\b]*?\\b/gi";
      String str = "This is the difficult one Thats it";
      System.out.println(str.matches(regex));
  
   }
  }
  </code></pre>
  
  <p>I am getting following <strong>Exception</strong>:</p>
  
  <pre><code>Exception in thread "main" java.util.regex.PatternSyntaxException:
  Illegal/unsupported escape sequence near index 7                                         
  /\bt[^\b]*?\b/gi                                                              
         ^                                                                      
          at java.util.regex.Pattern.error(Pattern.java:1924)                   
          at java.util.regex.Pattern.escape(Pattern.java:2416)                  
          at java.util.regex.Pattern.range(Pattern.java:2577)                   
          at java.util.regex.Pattern.clazz(Pattern.java:2507)                   
          at java.util.regex.Pattern.sequence(Pattern.java:2030)                
          at java.util.regex.Pattern.expr(Pattern.java:1964)                    
          at java.util.regex.Pattern.compile(Pattern.java:1665)                 
          at java.util.regex.Pattern.&lt;init&gt;(Pattern.java:1337)                  
          at java.util.regex.Pattern.compile(Pattern.java:1022)                 
          at java.util.regex.Pattern.matches(Pattern.java:1128)                 
          at java.lang.String.matches(String.java:2063)                         
          at HelloWorld.main(HelloWorld.java:8)
  </code></pre>
  
  <p>Also the following does not work:</p>
  
  <pre><code>import java.util.regex.*;
  public class HelloWorld{
  
   public static void main(String []args){
  
      String term = "t";
      String regex = "\\b"+term+"gi";
      //String regex = ".";
      System.out.println(regex);
      String str = "This is the difficult one Thats it";
      System.out.println(str.matches(regex));
  
  
       Pattern p = Pattern.compile(regex);
       Matcher m = p.matcher(str);
       System.out.println(m.find());
   }
  }
  </code></pre>
  
  <p>Example:
  { This , one, Two, Those, Thanks }
  for words This Two Those Thanks; result  should be true.</p>
  
  <p>Thanks</p>