C
Chris
All,
I have a question regarding pattern matching. In my class below an
argument String is taken in and compared to the name ‘chris’. If
‘chris’ is the only word in String s then the pattern checks out okay.
However, I’m wondering if it is possible to enter a sentence worth of
words and if ‘chris’ happens to be one of those words in the sentence
then the return is true otherwise false.
Thank you very much for your time.
______________________________________________________________
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NameCheck {
public static boolean patternMethod(String s) {
System.out.println(s);
Pattern p = Pattern.compile("chris");
Matcher m = p.matcher(s);
boolean isOk = m.matches();
return isOk;
}
}
I have a question regarding pattern matching. In my class below an
argument String is taken in and compared to the name ‘chris’. If
‘chris’ is the only word in String s then the pattern checks out okay.
However, I’m wondering if it is possible to enter a sentence worth of
words and if ‘chris’ happens to be one of those words in the sentence
then the return is true otherwise false.
Thank you very much for your time.
______________________________________________________________
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NameCheck {
public static boolean patternMethod(String s) {
System.out.println(s);
Pattern p = Pattern.compile("chris");
Matcher m = p.matcher(s);
boolean isOk = m.matches();
return isOk;
}
}