- 浏览: 140252 次
- 性别:
- 来自: 未来
-
文章分类
- 全部博客 (174)
- Eclispe (3)
- javaScript (33)
- SVG学习 (22)
- Java (21)
- 网站 (12)
- learn English (1)
- 文档 (25)
- 常用网站收录 (11)
- struts (6)
- 常用API (1)
- html (2)
- jsp (2)
- spring (2)
- IDE (1)
- 数据结构 (1)
- JDBC (2)
- html + css (1)
- xml (3)
- 心声 (1)
- Axis2 (1)
- svg (4)
- webService (2)
- unix (2)
- c/c++ (3)
- html5 (1)
- Android (2)
- Jet标签 (1)
- oracle (2)
- 工具 (1)
- ideas (0)
- lean plan (1)
- java技术网站,信息收集综合及分类 (0)
最新评论
-
calosteward:
感谢博主对svg convert to PDF资源的分享。我也 ...
How to Convert a SVG File to PDF Format -
long316:
fhhhh
WinArchiver 2.7 -
long316:
ddddd
WinArchiver 2.7
转自
http://www.mkyong.com/regular-expressions/10-java-regular-expression-examples-you-should-know/
Regular expression is an art of the programing, it’s hard to debug , learn and understand, but the powerful features are still attract many developers to code regular expression. Let’s explore the following 10 practical regular expression ~ enjoy
1. Username Regular Expression Pattern
^[a-z0-9_-]{3,15}$
^ # Start of the line
[a-z0-9_-] # Match characters and symbols in the list, a-z, 0-9 , underscore , hyphen
{3,15} # Length at least 3 characters and maximum length of 15
$ # End of the line
==> See the explanation and example here
2. Password Regular Expression Pattern
((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})
( # Start of group
(?=.*\d) # must contains one digit from 0-9
(?=.*[a-z]) # must contains one lowercase characters
(?=.*[A-Z]) # must contains one uppercase characters
(?=.*[@#$%]) # must contains one special symbols in the list "@#$%"
. # match anything with previous condition checking
{6,20} # length at least 6 characters and maximum of 20
) # End of group
==> See the explanation and example here
3. Hexadecimal Color Code Regular Expression Pattern
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
^ #start of the line
# # must constains a "#" symbols
( # start of group #1
[A-Fa-f0-9]{6} # any strings in the list, with length of 6
| # ..or
[A-Fa-f0-9]{3} # any strings in the list, with length of 3
) # end of group #1
$ #end of the line
==> See the explanation and example here
4. Email Regular Expression Pattern
^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+
(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$
^ #start of the line
[_A-Za-z0-9-]+ # must start with string in the bracket [ ], must contains one or more (+)
( # start of group #1
\\.[_A-Za-z0-9-]+ # follow by a dot "." and string in the bracket [ ], must contains one or more (+)
)* # end of group #1, this group is optional (*)
@ # must contains a "@" symbol
[A-Za-z0-9]+ # follow by string in the bracket [ ], must contains one or more (+)
( # start of group #2 - first level TLD checking
\\.[A-Za-z0-9]+ # follow by a dot "." and string in the bracket [ ], must contains one or more (+)
)* # end of group #2, this group is optional (*)
( # start of group #3 - second level TLD checking
\\.[A-Za-z]{2,} # follow by a dot "." and string in the bracket [ ], with minimum length of 2
) # end of group #3
$ #end of the line
==> See the explanation and example here
5. Image File Extension Regular Expression Pattern
([^\s]+(\.(?i)(jpg|png|gif|bmp))$)
( #Start of the group #1
[^\s]+ # must contains one or more anything (except white space)
( # start of the group #2
\. # follow by a dot "."
(?i) # ignore the case sensitive checking
( # start of the group #3
jpg # contains characters "jpg"
| # ..or
png # contains characters "png"
| # ..or
gif # contains characters "gif"
| # ..or
bmp # contains characters "bmp"
) # end of the group #3
) # end of the group #2
$ # end of the string
) #end of the group #1
==> See the explanation and example here
6. IP Address Regular Expression Pattern
^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.
([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$
^ #start of the line
( # start of group #1
[01]?\\d\\d? # Can be one or two digits. If three digits appear, it must start either 0 or 1
# e.g ([0-9], [0-9][0-9],[0-1][0-9][0-9])
| # ...or
2[0-4]\\d # start with 2, follow by 0-4 and end with any digit (2[0-4][0-9])
| # ...or
25[0-5] # start with 2, follow by 5 and end with 0-5 (25[0-5])
) # end of group #2
\. # follow by a dot "."
.... # repeat with 3 time (3x)
$ #end of the line
==> See the explanation and example here
7. Time Format Regular Expression Pattern
Time in 12-Hour Format Regular Expression Pattern
(1[012]|[1-9]):[0-5][0-9](\\s)?(?i)(am|pm)
( #start of group #1
1[012] # start with 10, 11, 12
| # or
[1-9] # start with 1,2,...9
) #end of group #1
: # follow by a semi colon (:)
[0-5][0-9] # follow by 0..5 and 0..9, which means 00 to 59
(\\s)? # follow by a white space (optional)
(?i) # next checking is case insensitive
(am|pm) # follow by am or pm
==> See the explanation and example here
Time in 24-Hour Format Regular Expression Pattern
([01]?[0-9]|2[0-3]):[0-5][0-9]
( #start of group #1
[01]?[0-9] # start with 0-9,1-9,00-09,10-19
| # or
2[0-3] # start with 20-23
) #end of group #1
: # follow by a semi colon (:)
[0-5][0-9] # follow by 0..5 and 0..9, which means 00 to 59
==> See the explanation and example here
8. Date Format (dd/mm/yyyy) Regular Expression Pattern
(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)
( #start of group #1
0?[1-9] # 01-09 or 1-9
| # ..or
[12][0-9] # 10-19 or 20-29
| # ..or
3[01] # 30, 31
) #end of group #1
/ # follow by a "/"
( # start of group #2
0?[1-9] # 01-09 or 1-9
| # ..or
1[012] # 10,11,12
) # end of group #2
/ # follow by a "/"
( # start of group #3
(19|20)\\d\\d # 19[0-9][0-9] or 20[0-9][0-9]
) # end of group #3
==> See the explanation and example here
9. HTML tag Regular Expression Pattern
<("[^"]*"|'[^']*'|[^'">])*>
< #start with opening tag "<"
( # start of group #1
"[^"]*" # only two double quotes are allow - "string"
| # ..or
'[^']*' # only two single quotes are allow - 'string'
| # ..or
[^'">] # cant contains one single quotes, double quotes and ">"
) # end of group #1
* # 0 or more
> #end with closing tag ">"
==> See the explanation and example here
10. HTML links Regular Expression Pattern
HTML A tag Regular Expression Pattern
(?i)<a([^>]+)>(.+?)</a>
( #start of group #1
?i # all checking are case insensive
) #end of group #1
<a #start with "<a"
( # start of group #2
[^>]+ # anything except (">"), at least one character
) # end of group #2
> # follow by ">"
(.+?) # match anything
</a> # end with "</a>
Extract HTML link Regular Expression Pattern
\s*(?i)href\s*=\s*(\"([^"]*\")|'[^']*'|([^'">\s]+));
\s* #can start with whitespace
(?i) # all checking are case insensive
href # follow by "href" word
\s*=\s* # allows spaces on either side of the equal sign,
( # start of group #1
"([^"]*") # only two double quotes are allow - "string"
| # ..or
'[^']*' # only two single quotes are allow - 'string'
| # ..or
([^'">]+) # cant contains one single / double quotes and ">"
) # end of group #1
==> See the explanation and example here
http://www.mkyong.com/regular-expressions/10-java-regular-expression-examples-you-should-know/
Regular expression is an art of the programing, it’s hard to debug , learn and understand, but the powerful features are still attract many developers to code regular expression. Let’s explore the following 10 practical regular expression ~ enjoy

1. Username Regular Expression Pattern
^[a-z0-9_-]{3,15}$
^ # Start of the line
[a-z0-9_-] # Match characters and symbols in the list, a-z, 0-9 , underscore , hyphen
{3,15} # Length at least 3 characters and maximum length of 15
$ # End of the line
==> See the explanation and example here
2. Password Regular Expression Pattern
((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})
( # Start of group
(?=.*\d) # must contains one digit from 0-9
(?=.*[a-z]) # must contains one lowercase characters
(?=.*[A-Z]) # must contains one uppercase characters
(?=.*[@#$%]) # must contains one special symbols in the list "@#$%"
. # match anything with previous condition checking
{6,20} # length at least 6 characters and maximum of 20
) # End of group
==> See the explanation and example here
3. Hexadecimal Color Code Regular Expression Pattern
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
^ #start of the line
# # must constains a "#" symbols
( # start of group #1
[A-Fa-f0-9]{6} # any strings in the list, with length of 6
| # ..or
[A-Fa-f0-9]{3} # any strings in the list, with length of 3
) # end of group #1
$ #end of the line
==> See the explanation and example here
4. Email Regular Expression Pattern
^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+
(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$
^ #start of the line
[_A-Za-z0-9-]+ # must start with string in the bracket [ ], must contains one or more (+)
( # start of group #1
\\.[_A-Za-z0-9-]+ # follow by a dot "." and string in the bracket [ ], must contains one or more (+)
)* # end of group #1, this group is optional (*)
@ # must contains a "@" symbol
[A-Za-z0-9]+ # follow by string in the bracket [ ], must contains one or more (+)
( # start of group #2 - first level TLD checking
\\.[A-Za-z0-9]+ # follow by a dot "." and string in the bracket [ ], must contains one or more (+)
)* # end of group #2, this group is optional (*)
( # start of group #3 - second level TLD checking
\\.[A-Za-z]{2,} # follow by a dot "." and string in the bracket [ ], with minimum length of 2
) # end of group #3
$ #end of the line
==> See the explanation and example here
5. Image File Extension Regular Expression Pattern
([^\s]+(\.(?i)(jpg|png|gif|bmp))$)
( #Start of the group #1
[^\s]+ # must contains one or more anything (except white space)
( # start of the group #2
\. # follow by a dot "."
(?i) # ignore the case sensitive checking
( # start of the group #3
jpg # contains characters "jpg"
| # ..or
png # contains characters "png"
| # ..or
gif # contains characters "gif"
| # ..or
bmp # contains characters "bmp"
) # end of the group #3
) # end of the group #2
$ # end of the string
) #end of the group #1
==> See the explanation and example here
6. IP Address Regular Expression Pattern
^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.
([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$
^ #start of the line
( # start of group #1
[01]?\\d\\d? # Can be one or two digits. If three digits appear, it must start either 0 or 1
# e.g ([0-9], [0-9][0-9],[0-1][0-9][0-9])
| # ...or
2[0-4]\\d # start with 2, follow by 0-4 and end with any digit (2[0-4][0-9])
| # ...or
25[0-5] # start with 2, follow by 5 and end with 0-5 (25[0-5])
) # end of group #2
\. # follow by a dot "."
.... # repeat with 3 time (3x)
$ #end of the line
==> See the explanation and example here
7. Time Format Regular Expression Pattern
Time in 12-Hour Format Regular Expression Pattern
(1[012]|[1-9]):[0-5][0-9](\\s)?(?i)(am|pm)
( #start of group #1
1[012] # start with 10, 11, 12
| # or
[1-9] # start with 1,2,...9
) #end of group #1
: # follow by a semi colon (:)
[0-5][0-9] # follow by 0..5 and 0..9, which means 00 to 59
(\\s)? # follow by a white space (optional)
(?i) # next checking is case insensitive
(am|pm) # follow by am or pm
==> See the explanation and example here
Time in 24-Hour Format Regular Expression Pattern
([01]?[0-9]|2[0-3]):[0-5][0-9]
( #start of group #1
[01]?[0-9] # start with 0-9,1-9,00-09,10-19
| # or
2[0-3] # start with 20-23
) #end of group #1
: # follow by a semi colon (:)
[0-5][0-9] # follow by 0..5 and 0..9, which means 00 to 59
==> See the explanation and example here
8. Date Format (dd/mm/yyyy) Regular Expression Pattern
(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/((19|20)\\d\\d)
( #start of group #1
0?[1-9] # 01-09 or 1-9
| # ..or
[12][0-9] # 10-19 or 20-29
| # ..or
3[01] # 30, 31
) #end of group #1
/ # follow by a "/"
( # start of group #2
0?[1-9] # 01-09 or 1-9
| # ..or
1[012] # 10,11,12
) # end of group #2
/ # follow by a "/"
( # start of group #3
(19|20)\\d\\d # 19[0-9][0-9] or 20[0-9][0-9]
) # end of group #3
==> See the explanation and example here
9. HTML tag Regular Expression Pattern
<("[^"]*"|'[^']*'|[^'">])*>
< #start with opening tag "<"
( # start of group #1
"[^"]*" # only two double quotes are allow - "string"
| # ..or
'[^']*' # only two single quotes are allow - 'string'
| # ..or
[^'">] # cant contains one single quotes, double quotes and ">"
) # end of group #1
* # 0 or more
> #end with closing tag ">"
==> See the explanation and example here
10. HTML links Regular Expression Pattern
HTML A tag Regular Expression Pattern
(?i)<a([^>]+)>(.+?)</a>
( #start of group #1
?i # all checking are case insensive
) #end of group #1
<a #start with "<a"
( # start of group #2
[^>]+ # anything except (">"), at least one character
) # end of group #2
> # follow by ">"
(.+?) # match anything
</a> # end with "</a>
Extract HTML link Regular Expression Pattern
\s*(?i)href\s*=\s*(\"([^"]*\")|'[^']*'|([^'">\s]+));
\s* #can start with whitespace
(?i) # all checking are case insensive
href # follow by "href" word
\s*=\s* # allows spaces on either side of the equal sign,
( # start of group #1
"([^"]*") # only two double quotes are allow - "string"
| # ..or
'[^']*' # only two single quotes are allow - 'string'
| # ..or
([^'">]+) # cant contains one single / double quotes and ">"
) # end of group #1
==> See the explanation and example here
发表评论
-
JAVA Servlet 动态加载配置文件.properties
2013-11-22 15:53 661JAVA Servlet 可以定义.properties文件对 ... -
常用的java类库
2013-11-14 15:03 532常用的java类库 http://www.programcr ... -
8种常见的Java不规范代码
2013-11-05 12:06 403http://www.oschina.net/question ... -
Java中String字符串的常见10个问题
2013-11-04 17:45 561Java中String字符串的常见10个问题 1:怎么比较字 ... -
JAVA核心技术8
2012-12-23 23:35 560JAVA核心技术8 -
Effective Java (目录)
2012-07-20 00:06 639http://www.cnblogs.com/stephen- ... -
json
2012-07-17 17:09 573http://564090701.iteye.com/blog ... -
java学习笔记
2012-07-15 14:34 617java学习笔记 -
java Comparator Example
2012-05-31 00:50 841http://www.javadeveloper.co.in/ ... -
Java内部类
2012-05-31 00:39 545Java内部类 从Java1.1开始引入了内部类以来,它就引起 ... -
Java String toUpperCase(Locale locale)Example
2012-05-31 00:34 1785http://www.codingdiary.com/deve ... -
NoClassDefFoundError
2012-04-25 15:34 563http://wolfdream.iteye.com/blog ... -
session持久化异常
2012-03-15 11:02 929http://www.iteye.com/topic/4128 ... -
session超时处理
2012-03-09 16:51 1303http://shmily2038.iteye.com/blo ... -
System.getProperty(String name)方法用于得到系统的属性.
2012-02-27 17:55 819http://www.iteye.com/topic/1029 ... -
J2Me,J2Se开发
2012-01-06 00:19 581J2ME手机开发基础 http://java.chinai ... -
java6 API
2011-12-20 11:49 934java6 API http://docs.oracle.c ... -
Json入门
2011-12-14 12:34 382http://blog.csdn.net/xiazdong/a ... -
java编程那些事
2011-10-21 16:57 584java编程那些事 http://blog.csdn.net/ ... -
==与equals的区别
2011-08-25 09:25 512http://12345678.iteye.com/blog/ ...
相关推荐
《OnJava8-Examples-3.0_soucecode_java_》是基于Java 8的一份源代码库,它对应于《Thinking in Java 5th Edition》这本书中的示例代码。这个压缩包包含了丰富的编程示例,旨在帮助读者深入理解Java 8的新特性以及...
这个“javacv-examples-0.7-src.zip”压缩包包含了用于学习如何在Java环境下使用JavaCV进行计算机视觉编程的源代码示例。这些示例对于初学者来说是非常宝贵的资源,可以帮助他们快速理解和应用JavaCV库。 OpenCV是...
这个名为"java_100examples.rar"的压缩包文件显然包含了100个Java编程示例,旨在帮助初学者理解并掌握Java编程的基础概念和技巧。下面我们将详细探讨这些Java小程序可能涵盖的知识点。 首先,基础语法是所有编程...
"Java_100examples.rar" 是一个专门为了帮助学习者深入理解和实践Java编程而编译的资源包,其中包含了100个精心挑选的Java实例,涵盖了从基础语法到高级特性的各种应用。 首先,让我们来看看这个压缩包中的...
本资源"Java Cryptography with Examples"提供了关于如何在Java环境中应用这些概念的详细教程。 首先,Java通过Java Cryptography Architecture (JCA) 和 Java Cryptography Extension (JCE) 提供了全面的加密支持...
《OnJava8-Examples-master》是一个关于Java 8编程实践的资源库,它包含了大量示例代码,旨在帮助开发者深入理解和应用Java 8的新特性。这个压缩包中的内容主要是为了展示如何在实际项目中有效利用Java 8的功能,...
**JAVA NUT 5 Examples 知识点详解** JAVA NUT 5 Examples 是一组与Java编程相关的示例代码,主要用于教学和实践。这个资源可能是Javanut系列教程的一部分,特别是第5版的内容。尽管描述中提到可能不完整,但它依然...
《第三版 Java Examples In A Nutshell》是一本深入浅出的Java编程教程,被誉为Java学习者的进阶之作。这本书由O'Reilly出版社出版,以其独特的"Nutshell"系列风格,为读者提供了丰富的代码示例和详尽的解释,旨在...
这份名为"java examples"的压缩包文件提供了丰富的Java编程示例,旨在帮助学习者深入理解和掌握Java标准库中的类以及它们的方法用法。这些例子涵盖了基础语法、数据类型、控制结构、类与对象、异常处理、集合框架、...
这个“javacv-examples-20121112-src”压缩包包含了2012年11月12日版本的JavaCV示例源代码,是学习和理解JavaCV功能和用法的重要资源。 JavaCV的核心目标是简化Java程序员在处理图像处理、视频分析和计算机视觉任务...
It begins with background on floating-point representation and rounding error, continues with a discussion of the IEEE floating-point standard, and concludes with numerous examples of how computer ...
"java网络编程examples.zip"这个压缩包很可能包含了一系列示例代码,帮助开发者理解和实践Java在网络编程中的应用。下面,我们将深入探讨Java网络编程的核心概念、常用API以及如何通过例子来学习。 1. Java网络编程...
"Java_examples.rar" 是一个包含100多个Java程序实例的压缩包,旨在帮助初学者深入理解和掌握Java编程技术。这个资源包特别关注了“progressbardemo.java”,这是一个关于进度条控件的示例,对于那些想学习如何在...
在本压缩包"Java3D-Examples.rar"中,包含了使用NetBeans构建的Java3D源代码示例。NetBeans是一个流行的开源集成开发环境(IDE),支持多种编程语言,包括Java,为开发者提供了便捷的代码编辑、调试和项目管理功能。...
这个"Java_examples.zip"压缩包包含的是专为初学者设计的100个Java示例程序,旨在帮助新接触Java编程的人快速掌握基础概念和实践技巧。 1. **面向对象编程**:Java的核心特性之一是它的面向对象编程(OOP)模型,...
【Java_Web_Examples-master】是一个关于Java Web开发的资源集合,主要包含了各种示例代码,帮助开发者理解和学习如何在实际项目中应用Java Web技术。这个压缩包可能包含了一个具体的项目——“超市库存管理系统”,...
《Java_Examples_in_a_Nutshell_3rd》是一本深受Java开发者喜爱的实战型书籍,第三版在原有的基础上进一步完善了对Java编程语言的深入解释。这本书以其丰富的示例和详细注解,帮助读者从实际操作的角度理解并掌握...
Java Examples in a Nutshell(3rd) 英文epub 第3版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除