Java正则表达式(总结二)
本次主要以例子为主:
1.匹配图像 /**
* 匹配图象 <br>
* 格式: /相对路径/文件名.后缀 (后缀为gif,dmp,png)
* 匹配 : /forum/head_icon/admini2005111_ff.gif 或 admini2005111.dmp<br>
* 不匹配: c:/admins4512.gif
*/
public static final String icon_regexp = "^(/{0,1}\\w){1,}\\.(gif|dmp|png|jpg)$|^\\w{1,}\\.(gif|dmp|png|jpg)$";
2.匹配邮件
/**
* 匹配email地址 <br>
* 格式: XXX@XXX.XXX.XX
* 匹配 : foo@bar.com 或 foobar@foobar.com.au <br>
* 不匹配: foo@bar 或 $$$@bar.com
*/
public static final String email_regexp = "(?:\\w[-._\\w]*\\w@\\w[-._\\w]*\\w\\.\\w{2,3}$)";
3.匹配并提取URL
/**
* 匹配匹配并提取url <br>
* 格式: XXXX://XXX.XXX.XXX.XX/XXX.XXX?XXX=XXX
* 匹配 : http://www.suncer.com 或news://www<br>
* 提取(MatchResult matchResult=matcher.getMatch()): matchResult.group(0)=
* http://www.suncer.com:8080/index.html?login=true matchResult.group(1) =
* http matchResult.group(2) = www.suncer.com matchResult.group(3) = :8080
* matchResult.group(4) = /index.html?login=true
* 不匹配: c:\window
*/
public static final String url_regexp = "(\\w+)://([^/:]+)(:\\d*)?([^#\\s]*)";
4.匹配并提取http
/**
* 匹配并提取http <br>
* 格式: http://XXX.XXX.XXX.XX/XXX.XXX?XXX=XXX 或 ftp://XXX.XXX.XXX 或
* https://XXX
* 匹配 : http://www.suncer.com:8080/index.html?login=true<br>
* 提取(MatchResult matchResult=matcher.getMatch()): matchResult.group(0)=
* http://www.suncer.com:8080/index.html?login=true matchResult.group(1) =
* http matchResult.group(2) = www.suncer.com matchResult.group(3) = :8080
* matchResult.group(4) = /index.html?login=true
* 不匹配: news://www
*/
public static final String http_regexp = "(http|https|ftp)://([^/:]+)(:\\d*)?([^#\\s]*)";
5.匹配日期
/**
* 匹配日期 <br>
* 格式(首位不为0): XXXX-XX-XX 或 XXXX XX XX 或 XXXX-X-X <br>
* 范围:1900--2099 <br>
* 匹配 : 2
相关文档:
初探java内存机制_堆和栈
问题的引入:
问题一:
String str1 = "abc";
String str2 = "abc";
System.out.println(str1==str2); //true
问题二:
String str1 =new String ("abc");
String str2 =new String ("abc");
System.out.println(str1==str2); // false
问题三:
String s1 = "ja";
String s2 = "v ......
package tf;
public class TestPack {
public static void main(String [] args)
{
try
{
IAnimal cAnimal = new bird();
cAnimal.shout();
IAnimal animal =(IAnimal)java.lang.Class ......
JDK1.5中的线程池(java.util.concurrent.ThreadPoolExecut
6
推荐
在多线程大师Doug Lea的贡献下,在JDK1.5中加入了许多对并发特性的支持,例如:线程池。
一、简介
线程池类为 java.util.concurrent.ThreadPoolExecutor,常用构造方法为:
ThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
long keepA ......
1)官方网站
在学习一个技术前直到官方网站是极为必要的,官方网站不但提供安装介质,而且有一手的技术参考资料。闲话简说 http://www.springsource.com/。 以前曾用过springframework.org,不知道为什么要改了名字。
2)经典参考书
有人推荐过Spring In Action, 我自己是从Spring Reference开始读的。
3)流行的版本
......
JAVA开发者最常去的20个英文网站
1.[http://www.javaalmanac.com] – Java开发者年鉴一书的在线版本. 要想快速查到某种Java技巧的用法及示例代码, 这是一个不错的去处.
2.[http://www.onjava.com] – O’Reilly的Java网站. 每周都有新文章.
3.[http://java.sun.com] – 官方的Java开发者网站 &ndash ......