1 package test_21_1; 2 3 import java.util.Arrays; 4 5 public class ExceptionTest { 6 7 public static void main(String[] args) { 8 9 String str = "Then, when you have found the shrubery, you must " + 10 "cut down the mightiest tree in the forest... " + 11 "with... a herring!"; 12 13 String regex = "(the|you) {1}"; 14 15 System.out.println(Arrays.toString(str.split(regex))); 16 17 String regex2 = "[aeiou]+"; 18 19 System.out.println(str.replaceAll(regex2, "_")); 20 } 21 }
结果如下:
[Then, when , have found , shrubery, , must cut down , mightiest tree in , forest... with... a herring!]
Th_n, wh_n y_ h_v_ f_nd th_ shr_b_ry, y_ m_st c_t d_wn th_ m_ght_st tr_ _n th_ f_r_st... w_th... _ h_rr_ng!