import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
String sentence = "Lorem ipsum dolor sit amet, consectetur ";
// Define a regular expression to match words
Pattern wordPattern = Pattern.compile("\\b\\w+\\b");
// Create a matcher for the input sentence
Matcher matcher = wordPattern.matcher(sentence);
// Count the number of words
int wordCount = 0;
while (matcher.find()) {
wordCount++;
}
System.out.println("The number of words is " + wordCount + ".");
}
}