java正则表达式模式匹配,Java正则表达式的模式匹配示例

package date0804.demo1;

import java.util.regex.Pattern;

public class RegularExpres {

public static void main(String[] args) {

//中括号只代表一位字符,*代表任意位,问号代表一位

//匹配首字母为a,末尾字母为b的任意字符串

boolean b1 = Pattern.matches("a*d", "aaaaad");

//匹配首字母为a,末尾字母为b的中间为任意一个字符(包括空字符)的任意字符串

boolean b2 = Pattern.matches("a?d", "ad");

//匹配首字母为a,末尾字母为b,中间为a或b或c的任意字符串

boolean b3 = Pattern.matches("a[abc]d", "abd");

//匹配首字母为a,末尾字母为b,中间为排除a或b或c的任意字符串

boolean b4 = Pattern.matches("a[^abc]d", "abd");

//匹配a-z或A-Z任意字符

boolean b5 = Pattern.matches("[a-zA-Z]", "a");

//a-d,m-p

boolean b6 = Pattern.matches("[a-dm-p]", "l");

//d,e,f

boolean b7 = Pattern.matches("[a-z&&[def]]", "d");

//a-d,m-p

boolean b8 = Pattern.matches("[a-dm-p]", "l");

//digit

boolean b9 = Pattern.matches("[0-9]", "?");

}

}

原文:http://my.oschina.net/zzw922cn/blog/487436

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值