Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1443105
  • 博文数量: 3500
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 43870
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-03 20:31
文章分类

全部博文(3500)

文章存档

2008年(3500)

我的朋友

分类:

2008-05-04 19:03:23

一起学习
import java.io.*; import java.util.regex.*; public class Printer { public static void main(String[] args) { System.out.println(" Please enter the input string: "); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String inputString; boolean isOK = false; try { while(!isOK) { if((inputString = reader.readLine()) != null) { if(inputString.length() > 200) { System.out.println("The string exceeds 200 characters. Please enter again! "); } else { Pattern regex = Pattern.compile("[^@#$%&*/^] "); Matcher matcher = regex.matcher(inputString); boolean isMatched = matcher.matches(); if(!isMatched) { System.out.println("The String cant contain @,#,$,%,*,& and ^. Please enter again! "); } else { isOK = true; System.out.println(" Your input string is: " inputString); } } } } } catch(IOException e) { e.printStackTrace(); } } } 下载本文示例代码


正则表达式的简单应用实例正则表达式的简单应用实例正则表达式的简单应用实例正则表达式的简单应用实例正则表达式的简单应用实例正则表达式的简单应用实例正则表达式的简单应用实例正则表达式的简单应用实例正则表达式的简单应用实例正则表达式的简单应用实例正则表达式的简单应用实例正则表达式的简单应用实例
阅读(137) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~