String pattern = ".*Q[^u]\\d+\\..*"; String line = "Order QT300. Now!"; if (Pattern.matches(pattern, line)) { System.out.println(line + " matches \"" + pattern + "\""); } else { System.out.println("NO MATCH"); }