整理常用的正则
邮箱正则 | \w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14} |
匹配中文 |
[\u4e00-\u9fa5] |
匹配双字节字符(包含汉字) |
[^\x00-\xff] |
匹配时间(时:分:秒) |
([01]?\d|2[0-3]):[0-5]?\d:[0-5]?\d |
匹配IP(IPV4) |
(\d+)\.(\d+)\.(\d+)\.(\d+) |
匹配*** |
\d{15}|\d{17}[0-9Xx] |
匹配日期(年-月-日) |
((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) |
匹配日期(年/月/日) |
((((1[6-9]|[2-9]\d)\d{2})/(0?[13578]|1[02])/(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})/(0?[13456789]|1[012])/(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) |
匹配正整数 |
[1-9]\d* |
匹配负整数 |
-[1-9]\d* |
-----------------------以下是邮箱正则在各类语言的基本实现代码---------------------------
邮箱正则 |
|
正则代码 | |
var pattern = /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/i, str = ''; console.log(pattern.test(str)); |
|
$str = ''; $isMatched = preg_match('/\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/i',$str,$matches); var_dump($isMatched,$matches); |
|
package main import ( "fmt" "regexp" ) func main() { str := "test" matched,err := regexp.MatchString("(?i)\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}",str) fmt.Println(matched,err) } |
|
pattern = /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/i str = '' p pattern.match(str) |
|
import re pattern = re.compile(ur'\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}',re.I) str = u'' print(pattern.search(str)) |
|
import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexMatches { public static void main(String args[]) { String str = ""; String pattern = "\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}"; Pattern r = Pattern.compile(pattern,Pattern.CASE_INSENSITIVE); Matcher m = r.matcher(str); System.out.println(m.matches()); } } |