gitee.com/zhongguo168a/gocodes@v0.0.0-20230609140523-e1828349603f/myx/regexputil/regexp.go (about) 1 package regexputil 2 3 // xy 匹配x y 4 // x|y 匹配x或者y 优先x 5 // source = "asdfdsxxxyyfergsfasfxyfa" 6 // pattern = `x|y|a` 7 8 //x* 匹配零个或者多个x,优先匹配多个 9 //x+ 匹配一个或者多个x,优先匹配多个 10 //x? 匹配零个或者一个x,优先匹配一个 11 12 //source = "xxxxewexxxasdfdsxxxyyfergsfasfxyfa" 13 //pattern = `x*` 14 15 // x{n,m} 匹配n个到m个x,优先匹配m个 16 // x{n,} 匹配n个到多个x,优先匹配更多 17 // x{n} 或者x{n}? 只匹配n个x 18 //source = "xxxxxxxewexxxasdfdsxxxyyfergsfasfxyfa" 19 //pattern = `x{4,}` 20 21 // x{n,m}? 匹配n个到m个x,优先匹配n个 22 // x{n,}? 匹配n个到多个x,优先匹配n个 23 // x*? 匹配零个或者多个x,优先匹配0个 24 // x+? 匹配一个或者多个x,优先匹配1个 25 // x?? 匹配零个或者一个x,优先匹配0个 26 //source = "xxxxxxxewexxxasdfdsxxxyyfergsfasfxyfa" 27 //pattern = `x??` 28 29 //[\d] 或者[^\D] 匹配数字 30 //[^\d]或者 [\D] 匹配非数字 31 //source = "xx435ff5237yy6346fergsfasfxyfa" 32 //pattern = `[\d]{3,}` //匹配3个或者更多个数字 33 34 //source = "xx435ffGUTEYgjk52RYPHFY37yy6346ferg6987sfasfxyfa" 35 //pattern = `[a-z]{3,}` //三个或者多个小写字母 36 37 //source = "xx435ffGUTEYgjk52RYPHFY37yy6346ferg6987sfasfxyfa" 38 //pattern = `[[:alpha:]]{5,}` //5个或者多个字母,相当于A-Za-z 39 40 // MatchName source = "xx435,./$%(*(_&jgshgs发个^$%ffG返回福hjh放假啊啥UTEYgjk52RYPHFY37yy6346ferg6987sfasfxyfa" 41 // pattern = `[\p{Han}]+` //匹配连续的汉字 42 // 匹配用户昵称 ^[\u4e00-\u9fa5]{4,8}$ 43 const MatchName = `^[_a-zA-Z0-9\p{Han}]*$` 44 45 //const MatchName = `^[_a-zA-Z0-9\p{Han}]+$` 46 47 // 匹配内容 48 const MatchContent = `^[!@#$%^&*\(\)_+~\{\}\[\]\<\>\,\.\?\/a-zA-Z0-9\p{Han}]+$` 49 50 // MatchPhone source = "13244820821HG74892109977HJA15200806084S11233240697hdgsfhah假发发货" 51 // pattern = `1[3|5|7|8|][\d]{9}` //匹配电话号码 52 const MatchPhone = `1[3|5|7|8|][\d]{9}` 53 54 //固定电话号码验证 55 const MatchTel = `^0\d{2,3}-?\d{7,8}$` 56 57 // MatchEmail source = "132@12.comGKGk15@163.cn200806084S11233240697hdgsfhah假发发货" 58 // pattern = `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*` //匹配电子邮箱 59 const MatchEmail = `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*` 60 61 // MatchUser 匹配用户名或者密码 `^[a-zA-Z0-9_-]{6,16}$` 字母或者数字开头,区分大小写,最短6位最长16位 62 const MatchUser = `^[a-zA-Z0-9_-]{6,16}$` 63 64 // MatchPwd 同上 65 //const MatchPwd = `^[a-zA-Z0-9_-]{6,16}$` 66 // asc码 可视字符 67 const MatchPwd = `^[\x21-\x7E]{6,64}$` 68 69 // MatchIP 匹配IP地址1 `^$(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$` 70 const MatchIP = `^$(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$` 71 72 // MatchIP2 匹配IP地址2 73 // pattern = `((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)` 74 const MatchIP2 = `((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)` 75 76 //匹配日期 年-月-日 `(\d{4}|\d{2})-((1[0-2])|(0?[1-9]))-(([12][0-9])|(3[01])|(0?[1-9]))` 77 //匹配日期 月-日-年 `((1[0-2])|(0?[1-9]))/(([12][0-9])|(3[01])|(0?[1-9]))/(\d{4}|\d{2})` 78 //匹配时间 小时:分钟 24小时制 ` ((1|0?)[0-9]|2[0-3]):([0-5][0-9]) ` 79 80 // MatchZIPCode 匹配邮编 `[1-9][\d]5` 81 const MatchZIPCode = `[1-9][\d]5` 82 83 // MatchURL 匹配URL `[a-zA-z]+://[^\s]*` 84 const MatchURL = `[a-zA-Z]+://[^\s]*` 85 86 // MatchUrlShort 匹配短的URL 87 const MatchUrlShort = `^[^\s]+$` 88 89 // MatchWOCode 匹配WO_CODE, 90 const MatchWOCode = `^[a-zA-Z0-9_-]+$` 91 92 // 银行卡 93 const MatchBankCard = `^[a-zA-Z0-9]{16,50}$`