码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-05-26 20:50:45      阅读:92      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!