import java.util.regex.*; import java.io.*; public class Print_matching_word { public static void main(String[] args) throws Exception { Pattern pattern = Pattern.compile("[0-9]+"); BufferedReader br = new BufferedReader (new FileReader("/home/girish/Desktop/D.txt")); String text; System.out.println("Words with digit 1 to 9 are:"); while ((text = br.readLine()) != null) { Matcher matcher = pattern.matcher(text); while (matcher.find()) { int start = matcher.start(0); System.out.println(text.substring(start)); } } } }