import java.util.regex.*; import java.io.*; public class SearchProgram{ public static void main(String[] args) throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter string in which we have to search: "); String string = in.readLine(); System.out.print("Enter string to search: "); String str = in.readLine(); Pattern pattern = Pattern.compile(str); Matcher matcher = pattern.matcher(string); int a = 0; while(matcher.find()){ a = a + 1; } if(a == 0) System.out.println("Word not found."); else System.out.println("Occurance of the word is: " + a); } }