You could try something like:
String string = " java is a programing language .java is robust and powerful and it is also platform independent. ";
String subS1 = "programing language";
subS1 = subS1.replace(" ", "\\s+");
Pattern p1 = Pattern.compile(subS1);
Matcher match1 = string.matcher(subS1);
String subS2 = "platform independent";
subS2 = subS2.replace(" ", "\\s+");
Pattern p2 = Pattern.compile(subS2);
Matcher match2 = string.matcher(subS2);
String subS3 = "robust and powerful";
subS3 = subS3.replace(" ", "\\s+");
Pattern p3 = Pattern.compile(subS3);
Matcher match3 = string.matcher(subS3);
if (match1.find() && match2.find() && match3.find()) {
// Whatever you like
}
You should replace all spaces in the substrings with '\s+', so it will also find "programing [loads of whitespaces] language".
Then compile the pattern you want to find and match the string and the substring. Repeat for each substring.
Lastly, test whether the matchers found anything.
Some Notes
- Didn't test it, but it should give an idea of how I should do it.
- Also, this should give an answer to you very specific question. This method should not be used when you have a large amount of substrings to check...
- Please post some code you were already working with, because now I feel like making your homework...