lua指定规则匹配字符
2014-11-07 16:14
274 查看
--是否是合格字符串 function isLegal(str) local len = string.len(str) local base = {} local basePregStr = "_,.!?;:" local basePregStrLen = string.len(basePregStr) for i=1,basePregStrLen do table.insert(base,string.byte(basePregStr,i,i)) end --0-9 a-z A-Z local numCode = string.byte("0",1,1) for i=1,10 do table.insert(base,numCode) numCode = numCode + 1 end local wordCode_lower = string.byte("a",1,1) local wordCode_upper = string.byte("A",1,1) for i=1,26 do table.insert(base,wordCode_lower) table.insert(base,wordCode_upper) wordCode_upper = wordCode_upper + 1 wordCode_lower = wordCode_lower + 1 end -- for k,v in pairs(base) do -- print(k,'=>',string.format("%c",v)) -- end function isInBase(n) local isIn = false for _,v in pairs(base) do if v == n then isIn = true break end end return isIn end local count = 0 for i=1,len do if count > 0 then count = count - 1 else print("i=>",i) local strNum = string.byte(str,i,i) if strNum < 127 then --汉字大于127 if isInBase(strNum) == false then print("不在base中",i) return false end else --判断是否 是汉字 而不是特殊字符 local s1 = strNum local s2 = string.byte(str,i+1,i+1) local s3 = string.byte(str,i+2,i+2) local s4 = s1..''..s2..''..s3 local num = tonumber(s4) -- 汉字4e00 9fa5 -- lua中的范围 228184128 233190165 if num < 228184128 or num > 233190165 then return false end count = 2 end end end return true end
相关文章推荐
- mysql正则匹配不包含指定字符
- cocos lua -字符串匹配规则。
- 如何用正则表达式匹配指定字符开始和指定字符结束
- lua字符匹配
- Lua实现在字符之间插入指定字符
- 正则表达式 匹配至少有一个非空白字符并且不超过指定长度
- lua 实现在字符之间插入指定字符
- Lua脚本语言中字符匹配模式详解
- 对整站的a链接进行监控,对匹配规则进行指定页面的跳转
- 匹配以指定字符开头元素:
- python re 正则表达式总结 匹配指定字符
- 字符串匹配替换(指定匹配位置)
- lua 含中文的字符串处理--分离字符、计算字符数、截取指定长度
- Lua 用指定字符或字符串分割输入字符串,返回包含分割结果的数组
- 正则表达式学习之四 指定匹配范围的字符
- python 查找文件夹下的指定部分路径下的所有文件内匹配的字符 包括子文件夹下的文件
- awk正则匹配列中指定的字符
- Asp.net的正则表达式,匹配指定的字符和字符串。
- 学习springmvc的第六天(@PathVariable 注解、Ant字符匹配、指定请求方式)
- Lua 字符串操作,截取指定字符串前后内容,lua 取指定字符左侧,或右侧内容