I have this working right and it does everything to a degree but when I search a file for a string that is gathered from user input it does not do it correctly. If you just type in one letter or number EX: 1 or d it finds the match if any and prints out the line that the match occurs in just fine and dandy. If there is no matches it breaks the loop and says no matches and that fine too. Am i missing something here when dealing with strings and the pattern matcher in java? Thanks for any help
public static void search() { LineNumberReader lineReader = null; try { String sStr; System.out.println("Enter your search term"); Scanner sScan = new Scanner(System.in); sStr = sScan.nextLine(); Pattern pat = Pattern.compile(sStr, Pattern.CASE_INSENSITIVE); System.out.println("Your searching for " + pat); lineReader = new LineNumberReader( new FileReader("Book-text.dat")); String line = null; while ((line = lineReader.readLine()) != null) { Matcher matcher = pat.matcher(line); if (matcher.find()) { String msg = "Found Match " + line; System.out.println(msg); }else{System.out.println("No Matches"); break;} matcher.reset(); } } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex){ ex.printStackTrace(); } finally { try { if (lineReader!= null) lineReader.close(); } catch (IOException ex) { ex.printStackTrace(); } } }