Validate Matches in Procedural Code (用程序码验证匹配)
来源:互联网 发布:淘宝号为什么会被限购 编辑:程序博客网 时间:2024/06/11 04:29
需求:
获取字符串Do you like 2, 3,4 , 6?中的2, 4, 6
方法:
1. Python
a. Global function
import re
subject = "Do you like 2, 3,4 , 6?"
result = []
for matchobj in re.finditer(r"\d+", subject):
if int(matchobj.group()) % 2 == 0:
result.append(matchobj.group())
print result
b. Compiled object
import re
subject = "Do you like 2, 3,4 , 6?"
result = []
reobj = re.compile("\d+")
for matchobj in reobj.finditer(subject):
if int(matchobj.group()) % 2 == 0:
result.append(matchobj.group())
print result
2. Tcl
set subject "Do you like 2, 3,4 , 6?"
set result ""
set pos 0
while {[regexp -indices -start $pos -linestop {\d+} $subject offsets]==1} {
set pos [expr {1+[lindex $offsets 1]}]
set sTmp [string range $subject [lindex $offsets 0] [lindex $offsets 1]]
if {$sTmp % 2 == 0} {
lappend result $sTmp
}
}
foreach i $result {
puts "$i"
}
- Validate Matches in Procedural Code (用程序码验证匹配)
- Replace Matches with Replacements Generated in Code (用函数作为替换体来替换匹配)
- struts的validate框架验证示例程序
- 13.2 匹配集合Matches
- 正则表达式-匹配matches
- Writing Remote Procedural Calls (RPCs) in C
- Procedural generated mesh in Unity: Part 1
- Procedural generated mesh in Unity: Part 2
- validate验证
- validate验证
- 用javase写一个简单的生成验证码图片的程序(verification code)
- ThinkPHP Validate 的验证码无法显示
- Unity Shader 学习笔记(17) 程序纹理(Procedural Texture)、程序材质(Procedural Materials)
- 用jquery.validate.js验证表单
- jquery validate.js表单验证(带验证码)
- [sig07][dice]Terrain Rendering in Frostbite using Procedural Shader Splatting
- How the Procedural Map Generation Works in Reactor Heart
- grep: highlighting matches in color
- Sublime Text 3 安装Package Control
- solr 忽略大小写
- .net编译目标平台
- JS 弹出层 定位至屏幕居中
- 聚集索引和非聚集索引
- Validate Matches in Procedural Code (用程序码验证匹配)
- 获取状态栏、标题栏的高度
- 将博客搬至CSDN
- bash学习笔记一
- netfilter框架分析
- 阻抗串并转换
- 代价函数(目标函数) cost function
- linux内核休眠与唤醒
- 银行业务调度系统