您的位置:首页 > 其它

Retrieve the match text (提取获取的字符)

2014-05-15 10:20 155 查看
需求:

获取字符串Do you like 12 or 34?中的12

方法:

1. Python

a. Global function

import re

match = re.search(r"\d+", subject)

if match:

result = match.group()

else:

result = ""

b. Compiled object

import re

reobj = re.compile(r"\d+")

match = reobj.search(subject)

if match:

result = match.group()

else:

result = ""

2. Tcl

regexp -linestop {\d+} $subject result
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐