title: How to find out a given string in a line using java
body: <p>I want find a Given sting in a line.For this I have wrote the code.I use the Pattern class to find the whether the give string is available in a line or not.It is gives the lines,those are not have given string.I want the lines those have the given string.Please check it my code.</p>
  
  <p>Code:</p>
  
  <pre><code> public class StringMatch {
    public static void main(String args[]) throws FileNotFoundException, IOException{
      String text="dsfhgs the dgfre fh" +
                  "hjfgeh fhg hghjr" +
                  "fhvhjf the vgh fhjghf" +
                  "fbvhjfd  fhvfg fjvhf" +
                  "the hfdvhjf vhf  fhdvjfd" +
                  "hfvbhd thehjdvhj hdfvhdf";
      String pattern = ".*?\\the\\b.*?";
      String f="C:\\TextFiles\\sample.txt";
      String line;
      BufferedReader br = new BufferedReader(new FileReader(f));
      while(br.readLine()!=null) {
          line=br.readLine();
          Pattern r = Pattern.compile(pattern);
          Matcher m = r.matcher(line);
          if (m.find( )) {
              System.out.println("Found value: " + m.group(0) );
              System.out.println("Found value: " + m.group(1) );
              System.out.println("Found value: " + m.group(2) );
          } else {
              System.out.println("NO MATCH");
      }
      }
   }
  }
  </code></pre>