Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re:freshlll]
rebirth





发贴: 17
积分: 0
于 2004-09-14 14:24 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
一般使用正则表达对给出的字符串进行判断, 看其是否符合正则表达式的规则.
如下例所示 :
import java.util.regex.*;
public class FormatPattern {
final static String NOTNEGINT="^\\d+$";  //非负整数
private FormatPattern(){}
private static Pattern p=null;
private static Matcher m=null;
/**
*
* @author Ryan rebirth@21cn.net
* @2004-8-12
* TODO 判断是否是正整数
* @param str
* @return
* boolean
*/
public static boolean notNegInt(String str){
return check(str,NOTNEGINT);
}
/**
* @author Ryan rebirth@21cn.net
* @2004-8-12
* TODO 判断函数(私有)
* @param str
* @param chkPattern
* @return
* boolean
*/
private static boolean check(String str,String chkPattern){
p=Pattern.compile(chkPattern);
m=p.matcher(str);
return m.matches();
}
}

p=Pattern.compile(String sPattern) 设置样式
m=p.matcher(str) 设置匹配器
m.matches() 看该字符串是否匹配




加入CJSDN真好!

话题树型展开
人气 标题 作者 字数 发贴时间
7774 那位大哥能谈一谈java.util.regex.Pattern的用法? freshlll 35 2004-09-09 12:06
6577 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? lnsylt 8 2004-09-09 17:14
6613 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? freshlll 10 2004-09-20 15:20
6555 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? jmd7 98 2004-09-30 16:01
6724 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? didongusa 235 2004-09-10 07:08
6882 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? freshlll 74 2004-09-10 13:12
6646 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? didongusa 62 2004-09-10 19:59
6694 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? think 56 2004-09-12 13:52
6605 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? jameszhang 63 2004-09-10 23:41
6590 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? why 281 2004-09-11 04:31
6628 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? ww1ww1 78 2004-09-12 20:38
6537 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? why 322 2004-09-12 21:05
6634 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? ww1ww1 444 2004-09-12 22:34
6469 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? why 260 2004-09-12 22:41
6740 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? bluepure 768 2004-09-14 14:08
7430 Re:那位大哥能谈一谈java.util.regex.Pattern的用法? rebirth 945 2004-09-14 14:24

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923