The way it works is, that the user will paste a text into the cmd and then he can choose one of the program options. One of them is find specific word/phrase in text. This is the code I have for this section:
public void searching() {
System.out.println("Enter the word you wish to find");
Pattern pattern = Pattern.compile(scan.next());
Matcher matcher = pattern.matcher(text);
boolean found = false;
while (matcher.find()) {
System.out.println("I found the text "+pattern+" starting at index "+
matcher.start()+" and ending at index "+matcher.end());
found = true;
}
if(!found){
System.out.println("No match found.");
}
}
My problem is that if the user's text is for example "lorem ipsum dolor sit amet" and they want to find where the word "dolor" is, the output is "no match found". The program will only find the word lorem if the user asks for it.
The other question is: is there a way to make the output be not the index of the found word but the whole text and the found word in the upper case?