Topic: 那位大哥能谈一谈java.util.regex.Pattern的用法?

  Print this page

1.那位大哥能谈一谈java.util.regex.Pattern的用法? Copy to clipboard
Posted by: freshlll
Posted on: 2004-09-09 12:06

那位大哥能谈一谈java.util.regex.Pattern的用法?

2.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: freshlll] Copy to clipboard
Posted by: lnsylt
Posted on: 2004-09-09 17:14

没用过,关注!!

3.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: freshlll] Copy to clipboard
Posted by: didongusa
Posted on: 2004-09-10 07:08

Hello, freshlll:

You enter the wrong door. That's core java not web app.

The java.util.regex deals about regular expression, for a word you can search a kind of pattern, and replace or somehow delete. I have no interest about it.

4.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: freshlll] Copy to clipboard
Posted by: freshlll
Posted on: 2004-09-10 13:12

上面那位大哥说得不完全确,我在java的wep app 中会经常用这个class.这个class.可用过滤。而过滤在web 的交互式开发中是很重要的

5.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: freshlll] Copy to clipboard
Posted by: didongusa
Posted on: 2004-09-10 19:59

Filter you mean, may be used in presentation logic.

Thanks.

6.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: freshlll] Copy to clipboard
Posted by: jameszhang
Posted on: 2004-09-10 23:41

http://www.cjsdn.net/post/view?bid=1&id=23446&sty=1&tpg=1&age=0

7.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: freshlll] Copy to clipboard
Posted by: why
Posted on: 2004-09-11 04:31

The Java Tutorial
Lesson: Regular Expressions
http://java.sun.com/docs/books/tutorial/extra/regex/

Regular Expressions and the Java Programming Language
http://java.sun.com/developer/technicalArticles/releases/1.4regex/

you can find many many more with any search engine.

8.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: didongusa] Copy to clipboard
Posted by: think
Posted on: 2004-09-12 13:52

推荐O'Reilly - Mastering Regular Expressions(2nd). 这本书值得一读

9.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: freshlll] Copy to clipboard
Posted by: ww1ww1
Posted on: 2004-09-12 20:38

How to got this e-version of O'Reilly - Mastering Regular Expressions(2nd) ?

10.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: ww1ww1] Copy to clipboard
Posted by: why
Posted on: 2004-09-12 21:05

ww1ww1 wrote:
How to got this e-version of O'Reilly - Mastering Regular Expressions(2nd) ?

Please do a search on Google.
The first edition is good enough
I found this on the first result page
http://bookshelf.sleepnet.net/files/%5Bebook%5D%20OReilly%20-%20Mastering%20Regular%20Expressions.pdf

11.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: why] Copy to clipboard
Posted by: ww1ww1
Posted on: 2004-09-12 22:34

why wrote:
Please do a search on Google.
The first edition is good enough
I found this on the first result page
http://bookshelf.sleepnet.net/files/%5Bebook%5D%20OReilly%20-%20Mastering%20Regular%20Expressions.pdf


But I wonder how could you find that link,
as I search the key word " Mastering Regular Expressions" with Google, it just return some links which link to some bookshops or introduction of that book.

12.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: ww1ww1] Copy to clipboard
Posted by: why
Posted on: 2004-09-12 22:41

ww1ww1 wrote:
But I wonder how could you find that link,
as I search the key word " Mastering Regular Expressions" with Google, it just return some links which link to some bookshops or introduction of that book.

keywords: ebook or 电子书

13.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: freshlll] Copy to clipboard
Posted by: bluepure
Posted on: 2004-09-14 14:08


import java.util.regex.*;

public class VerifyTool {
private static Pattern emailPattern = null;
private VerifyTool() {
}
/**
* 检验一个字符串是否是合法的Email地址。
* @param aString String
* @return boolean
*/
public static boolean isValidEmail(String aString) {
if (aString == null || aString.length() < 9) {
//至少应该五个字符比如:a@b.c ,但是一般来说9个字母的email地址都不存在。
//因为根据域名规则,'@'后面至少应该有6位(比如aaa.cn,
//根域名至少两个字符,且只能够是字母。顶级域名至少3个字符,加是分隔符,就是6个字符了
//用户名只有一位或者两位的基本没有,可以当作不存在的用户)
return false;
}
if (emailPattern == null) {
emailPattern = Pattern.compile(
"^[\\w-.]+@([\\w-]+.)*([\\w-]{3,20}+.)+[a-zA-Z]{2,4}$");
}
return emailPattern.matcher(aString).find();
}
}


14.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: freshlll] Copy to clipboard
Posted by: rebirth
Posted on: 2004-09-14 14:24

一般使用正则表达对给出的字符串进行判断, 看其是否符合正则表达式的规则.
如下例所示 :
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() 看该字符串是否匹配

15.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: freshlll] Copy to clipboard
Posted by: freshlll
Posted on: 2004-09-20 15:20

好多热心人呀!感谢!

16.Re:那位大哥能谈一谈java.util.regex.Pattern的用法? [Re: freshlll] Copy to clipboard
Posted by: jmd7
Posted on: 2004-09-30 16:01

Oreilly那本书确实非常详尽全面,不过对于一般的Java开发内容太过丰富了,一般性的了解就上面的Sun的Tutorial或者Manning的JDK14的新特性中的Regex那一章也就差不多了。


   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