Java 正则表达式 zz
确定一个串是否包含另一个串下文摘自(http://www.javaref.cn/egs/java.lang/HasSubstr.html)
String string = "Madam, I am Adam";
// Starts with
boolean b = string.startsWith("Mad"); // true
// Ends with
b = string.endsWith("dam"); // true
// Anywhere
b = string.indexOf("I am") > 0; // true
// To ignore case, regular expressions must be used
// Starts with
b = string.matches("(?i)mad.*");
// Ends with
b = string.matches("(?i).*adam");
// Anywhere
b = string.matches("(?i).*i am.*");
http://www.lifevv.com/hechushi521/doc/20070511174237468.html?page=0 这个很详细 表达式 说明 使用例 ^ 匹配一行的开头。 例:1,^hello。匹配行头以hello开头的字符串。 $ 匹配一行的结尾 例:1,hello$。匹配行尾以hello结尾的字符串。 . 匹配改行以外的任何字符 例:1,hello.world。匹配诸如hello world,hello-world等字符串。 匹配被括起来的任何一个字符 例:1,。匹配a或者b或者c。 2,rd。匹配rad或red或rud。 匹配从A-Z的任一个字符。 例:1,ac。匹配aAc,aBc,…,aZc。 匹配从a-z的任一个字符。 例:1,ac。匹配aac,abc,…,azc。 匹配从0-9的任一个数字。 例:1,ac。匹配a0c,a1c,…,a9c。 匹配任何没有被括起来的一个字符。与相左。 例:1,。则匹配除a或b或c以外的其他字符。
正则表达式 java.util.regex 常用正则表达式 下面列出一些常用的正则表达式: ^\d+$ //非负整数(正整数 + 0) ^$ //正整数 ^((-\d+)|(0+))$ //非正整数(负整数 + 0) ^-$ //负整数 ^-?\d+$ //整数 ^\d+(\.\d+)?$ //非负浮点数(正浮点数 + 0) ^((+\.)|(\.+)|())$ //正浮点数 ^((-\d+(\.\d+)?)|(0+(\.0+)?))$ //非正浮点数(负浮点数 + 0) ^(-((+\.)|(\.+)|()))$ //负浮点数 ^(-?\d+)(\.\d+)?$ //浮点数 ^+$ //由26个英文字母组成的字符串 ^+$ //由26个英文字母的大写组成的字符串 ^+$ //由26个英文字母的小写组成的字符串 ^+$ //由数字和26个英文字母组成的字符串 ^\w+$ //由数字、26个英文字母或者下划线组成的字符串 ^+(\.+)@+(\.+)+$ //email地址 ^+://(\w+(-\w+))(\.(\w+(-\w+)))(\?\S*)?$ //url
^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$ // 时间,如 13:04:06 ^(\d{1,4})(-|/)(\d{1,2})\2(\d{1,2})$ // 日期,如 2003-12-05 ^(\d{1,4})(-|/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$ // 日期 2003-12-05 13:04:06 ^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$ // 15位的身份证 ^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\d)$ // 18位的身份证