. 匹配任意一个字符

* 表示匹配0个或多个前面这个字符

+ 表示1个或多个前面这个字符

? 表示0个或1个前面这个字符

^ 表示一行的开始   ^[a-zA-Z] :表示开头是a-z或者A-Z

  [^0-9] :表示不是数字,除数字以外的

$ 表示一行的结束

\w 表示词字符[a-zA-Z0-9]

\W 表示非词字符[^\w]

第七题:

  package net.mindview.strings.test7;
public class Test7 {

    public static void main(String[] args) {
//两种写法都可以
String regex = "^[A-Z].*\\.$";//"^[A-Z].*\\."这样也对
String regex1 = "\\p{Upper}.*\\.$";
String str = "D.";
String str1 = "Dfasdfasfasfdasfdasfasfasdf.";
String str2 = "Dfasdfasfasfdasfdasfasfasdf.E";
System.out.println(str.matches(regex));
System.out.println(str1.matches(regex));
System.out.println(str2.matches(regex));
System.out.println(str.matches(regex1));
System.out.println(str1.matches(regex1));
System.out.println(str2.matches(regex1));
}
}

运行结果:

  true
true
false
true
true
false

第八题

package net.mindview.strings;

import java.util.Arrays;

public class Splitting {

    public static String knights = "Then, when you have found the shrubbery, you must cut down the mightiest tree in the forest... with... a herring!";

    public static void split(String regex){
System.out.println(Arrays.toString(knights.split(regex)));
}
public static void main(String[] args) {
//表示的时按照空格分割字符串
//运行结果:[Then,, when, you, have, found, the, shrubbery,, you, must, cut, down, the, mightiest, tree, in, the, forest..., with..., a, herring!]
split(" "); //表示按照非单次字符分割字符串--这里的非单次字符是空格和,
//运行结果:[Then, when, you, have, found, the, shrubbery, you, must, cut, down, the, mightiest, tree, in, the, forest, with, a, herring]
split("\\W+");
//这个表示:费单次字符之前带n的地方进行分割字符串 这里的分割符是n空格和n,
//运行结果:[The, whe, you have found the shrubbery, you must cut dow, the mightiest tree i, the forest... with... a herring!]
split("n\\W+");
} }
package net.mindview.strings.test8;

import net.mindview.strings.Splitting;

public class Test8 {

    public static void main(String[] args) {
String regex = "the|you";
Splitting.split(regex);
}
}

第九题

package net.mindview.strings.test9;

import net.mindview.strings.Splitting;

public class Test9 {
public static void main(String[] args) {
String regex = "A|E|I|O|U|a|e|i|o|u";
//通过嵌入式标志表达式 (?i) 也可以启用不区分大小写的匹配。
String regex1 = "(?i)a|e|i|o|u";
//[abc] 表示a或b或c
String regex2 = "(?i)[aeiou]";
System.out.println(Splitting.knights.replaceAll(regex, "_"));
System.out.println(Splitting.knights.replaceAll(regex1, "_"));
System.out.println(Splitting.knights.replaceAll(regex2, "_"));
}
}

java编程思想-第13章-某些练习题的更多相关文章

  1. java编程思想-第六章-某些练习题

    参考https://blog.csdn.net/caroline_wendy/article/details/47271037 3 package debug; import java.util.Ar ...

  2. java编程思想-第五章-某些练习题

    参考https://blog.csdn.net/caroline_wendy/article/details/46844651 10&11 finalize()被调用的条件 Java1.6以下 ...

  3. Java编程思想 第21章 并发

    这是在2013年的笔记整理.现在重新拿出来,放在网上,重新总结下. 两种基本的线程实现方式 以及中断 package thread; /** * * @author zjf * @create_tim ...

  4. Java编程思想——第17章 容器深入研究 读书笔记(三)

    七.队列 排队,先进先出. 除并发应用外Queue只有两个实现:LinkedList,PriorityQueue.他们的差异在于排序而非性能. 一些常用方法: 继承自Collection的方法: ad ...

  5. Java编程思想——第17章 容器深入研究(two)

    六.队列 排队,先进先出.除并发应用外Queue只有两个实现:LinkedList,PriorityQueue.他们的差异在于排序而非性能. 一些常用方法: 继承自Collection的方法: add ...

  6. Java编程思想-第四章练习题

    练习1:写一个程序,打印从1到100的值 public class Print1To100{ public static void main(String args[]){ for(int i = 1 ...

  7. Java编程思想笔记(第二章)

    第二章  一切都是对象 尽管Java是基于C++的,但相比之下,Java是一种更纯粹的面向对象程序设计语言. c++和Java都是杂合型语言(hybird language) 用引用(referenc ...

  8. java编程思想笔记(第一章)

    Alan Kay 第一个定义了面向对象的语言 1.万物皆对象 2.程序是对象的集合,他们彼此通过发送消息来调用对方. 3.每个对象都拥有由其他对象所构成的存储 4.每个对象都拥有其类型(TYpe) 5 ...

  9. Java编程思想第七章复用类

    7.1组合语法 在一个类中引入多个对象,以提高代码的复用性与功能. 7.2继承语法 使用继承子类可以获得,导出类可以获得基类的成员(变量与方法). 注:这里注意权限控制,若基类中的成员为默认权限,只有 ...

随机推荐

  1. Redis的集群配置

    如果我们redis的压力很大,如果我们的并发高到我们读数据和写数据都有了很大压力. 那么我们可能就需要把redis分开部署,并且配置为一个『主从』的状态. 在服务器上构筑Redis的集群配置: 1.切 ...

  2. RecyclerView 与 Scrollview 搭配使用的两个坑

    RecyclerView & Scrollview & wrap_content RecyclerView wrap_content 用android.support.v4.widge ...

  3. CSS3实现多样的边框效果

    半透明边框 实现效果: 实现代码: <div> 你能看到半透明的边框吗? </div> div { /* 关键代码 */ border: 10px solid rgba(255 ...

  4. IE中调试JS的一款很好的工具

    附件是 IE中调试JS的一款很好用的工具,欢迎下载使用.  具体使用方法为:  1.先安装Companion.JS文件(install.exe).  2.安装Microsoft Script Debu ...

  5. 新一代大数据处理引擎 Apache Flink

    https://www.ibm.com/developerworks/cn/opensource/os-cn-apache-flink/index.html 大数据计算引擎的发展 这几年大数据的飞速发 ...

  6. Fast Paxos

    http://blog.csdn.net/chen77716/article/details/7297122 自从Lamport在1998年发表Paxos算法后,对Paxos的各种改进工作就从未停止, ...

  7. Python循环依赖问题的解决

    一个是把某个import移到代码中间,使原先的循环依赖圈打开.

  8. Ubuntu 下命令安装 Java

    1. 使用 java -version 查看系统是否存在 jdk. 2. ubuntu使用的是openjdk,所以我们需要先找到合适的jdk版本.在命令行中输入命令:apt-cache search ...

  9. Kali学习笔记4:Wireshark详细使用方法

    Kali Linux自带Wireshark工具使用介绍: 1.进入界面 这里Lua脚本报错,无需关注 开始使用: 双击第一个eth0:以太网0,开始抓包: 点击上边的这个按钮可以设置: 这里注意:需要 ...

  10. Java多线程:线程与进程

    实际上,线程和进程的区别,在学OS时必然是学习过的,所缺的不过是一些总结. 1. 进程 2. 线程 3. 进程与线程 4. 多进程与多线程对比 5. Java多进程与多线程 5.1. Java多进程 ...