Java tutorial
import java.io.BufferedReader; import java.io.FileReader; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] argv) throws Exception { String filename = "infile.txt"; String patternStr = "pattern"; BufferedReader rd = new BufferedReader(new FileReader(filename)); Pattern pattern = Pattern.compile(patternStr); Matcher matcher = pattern.matcher("\\D"); String line = null; while ((line = rd.readLine()) != null) { matcher.reset(line); if (matcher.find()) { // line matches the pattern } } } }