正文

正则表达式的几个有用的例子2008-08-18 20:15:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/iamben250/37694.html

分享到:

Expression
ISBN(-1(?:(0)|3))?:?\x20+(?(1)(?(2)(?:(?=.{13}$)\d{1,5}([ -])\d{1,7}\3\d{1,6}\3(?:\d|x)$)|(?:(?=.{17}$)97(?:8|9)([ -])\d{1,5}\4\d{1,7}\4\d{1,6}\4\d$))|(?(.{13}$)(?:\d{1,5}([ -])\d{1,7}\5\d{1,6}\5(?:\d|x)$)|(?:(?=.{17}$)97(?:8|9)([ -])\d{1,5}\6\d{1,7}\6\d{1,6}\6\d$)))
Description
This regex match both the old 10 digit ISBNs and the new 13 digit ISBNs. The ISBN number must be prefixed by the literal text "ISBN:" or "ISBN-10:" or "ISBN-13:". The colon is optional. Naturally an ISBN prefixed by "ISBN-10" must be a 10 digit ISBN. One prefixed by "ISBN-13" must be 13 digits. If prefixed only by "ISBN:" it can be either 10 or 13 digits. This does not evaluate whether the check digit is valid for the given ISBN. The structure of an ISBN is discribed here http://www.isbn.org/standards/home/isbn/international/html/usm4.htm (this is for 10 digit)
Matches
ISBN-13: 978-1-4028-9462-6
Non-Matches
ISBN: 1284233-2-1-1

 

Title Test Details Validate very strong password
Expression
^(?=^.{8,}$)(?=.*\d)(?=.*\W+)(?=.*[a-z])(?=.*[A-Z])(?i-msnx:(?!.*pass|.*password|.*word|.*god|.*\s))(?!^.*\n).*$
Description
This regular expression can be used to validate a strong password. It will evaluate to true if the following critera are met: Must be 8 characters in length total. Must contain at least 1 digit. Must contain at least 1 lower case letter. Must contain at least 1 upper case letter. Must contain at least 1 non-character (such as !,#,%,@, etc). Must not contain the words "password" or "pass" or "word" or "god" Must not contain a whitespace. Note: This version is not compatible with JavaScript
Matches
one2!fouR, @Eight21, one22Four%, 2thRee@four, 7diPity*, 12345aB(
Non-Matches
one2three!, four2345, #viced@#$, short1@

Expression
^(((((0?[1-9])|(1\d)|(2[0-8]))\.((0?[1-9])|(1[0-2])))|((31\.((0[13578])|(1[02])))|((29|30)\.((0?[1,3-9])|(1[0-2])))))\.((20[0-9][0-9]))|(29\.0?2\.20(([02468][048])|([13579][26]))))$
Description
Regular expression to evaluate a date in German date format (DD.MM.YYYY). Leading zeros for days and months are valid. Period from 1.1.2000 until 31.12.2099 is valid. Leap years are checked.
Matches
1.1.2000 | 29.02.2004 | 31.12.2099
Non-Matches
1.1.1999 | 29.02.2003 | 01.01.2100

Title Test Details Roman numerials
Expression
^(?i:(?=[MDCLXVI])((M{0,3})((C[DM])|(D?C{0,3}))?((X[LC])|(L?XX{0,2})|L)?((I[VX])|(V?(II{0,2}))|V)?))$
Description
This RE validates alpha characters that evaluate to Roman numerials, ranging from 1(I) - 3999(MMMCMXCIX). Not case sensitive.
Matches
III | xiv | MCMXCIX
Non-Matches
iiV | MCCM | XXXX

 

阅读(1896) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册