I have been doing this since almost past few days but still unable to get a required output.
Well I have an array say
wordlist[]={"One","Two","Three","Four","Five"};
and then i take input from the user.
String input="I have three no, four strings";
Now what i want to do is perform a search operation on the string to check for the words available in the array wordlist[]; Like in the above example input string contains the words three and four that are present in the array. so it should be able to print those words from array available in the string, and if no words from the wordlist[] are available then it should print "No Match Found".
Here's My code i'm struck with this. Please
import java.util.regex.*;
import java.io.*;
class StringSearch{
public static void main(String ...v)throws IOException{
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
String wordlist[]={"one","two","three","four","five"};
String input=cin.readLine();
int i,j;
boolean found;
Pattern pat;
Matcher mat;
Pattern spliter=Pattern.compile("[ ,.!]");
String ip[]=spliter.split(input);
System.out.println(ip[2]);
for(i=0; i<wordlist.length;i++){
for(j=0;j<ip.length;j++){
pat=Pattern.compile("\b"+ip[j]+"\b");
mat=pat.matcher(wordlist[i]);
if(){
// No Idea What to write here
}
}
}
}
}
mat.matches(). In the if body increment a counting integer and use it outside the for loops to print "no match found" in case of zero matches. Also check that"\b"+ip[j]+"\b"regex, it doesn't work to mematchesadd^and$so it should be the complete match