first a bit of code:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WordsWithSpaces {
public static void main(String[] args) {
String test = "Descent D escent De s cent desce nd";
String word = "descent";
String pattern = "";
for(int i=0; i<word.length();i++) {
pattern = pattern+word.charAt(i)+"\\s*";
}
System.err.println("pattern is: "+pattern);
Pattern p = Pattern.compile(pattern,Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(test);
while(m.find()) {
String found = test.substring(m.start(),m.end());
System.err.println(found+" matches");
}
}
}
now for the explanation: \s is a character class for whitespace. this includes spaces and tabs and (possibly) linebreaks. in this piece of code, i take every character of the word i am looking for, and append "\s", with "*" meaning 0 or mor occurences.
also, to avoid it being case sensitive, i set the CASE_INSENSITIVE flag on the pattern.
character classes may not have the same name in your programming language of choice, but there should be one for whitespace. check your documentation.