[20-05-26][Thinking in Java 43]Java String 1 - Regular Exception 1

2021-01-07 19:33

阅读:717

标签:exce   tostring   sys   tree   oid   cep   test   java   regex   

 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!

[20-05-26][Thinking in Java 43]Java String 1 - Regular Exception 1

标签:exce   tostring   sys   tree   oid   cep   test   java   regex   

原文地址:https://www.cnblogs.com/mirai3usi9/p/12968225.html


评论


亲,登录后才可以留言!