What will be the output of the following snippet of code:
String source = "I saw she said sake."; String regex = "s.."; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(source); while(m.find()) { System.out.println(m.group()); }
saw she sai sak
Complete the following snippet of code that will match two words-cat and cot in the input. When the code is run, it should print cat and cot on two separate lines.'
String source = "cat camera can date cute cab cot"; String regex = /* Your code goes here */; Pattern p = Pattern.compile(regex); Matcher m = /* Your code goes here */; while(m.find()) { System.out.println(m.group()); }
String source = "cat camera can date cute cab cot";
String regex = "c[ao]t";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(source);
while(m.find()) {
System.out.println(m.group());
}Complete the following snippet of code that will replace all three-letter words that start with c with their uppercase equivalents.
The code should print "DIG DATe DEAd do DID DONe".
String source = "dig date dead do did done"; String regex = "/* You code goes here*/"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(source); String str = m.replaceAll(mr -> mr.group().toUpperCase()); System.out.println(str);
String source = "dig date dead do did done";
String regex = "d[a-z]{2}";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(source);
String str = m.replaceAll(mr -> mr.group().toUpperCase());
System.out.println(str);PreviousNext