加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Retrieve a list of all matches (提取所有匹配的列表)

发布时间:2020-12-14 01:46:17 所属栏目:百科 来源:网络整理
导读:需求: 获取字符串Do you like 12 or 34?中的12, 34 方法: 1. Python a. Global function import re subject = "Do you like 12 or 34?" result = re.findall(r"d+",subject) b. Compiled object import re reobj = re.compile(r"d+") result = reobj.fi

需求:

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


方法:

1. Python

a. Global function

import re

subject = "Do you like 12 or 34?"

result = re.findall(r"d+",subject)

b. Compiled object

import re

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

result = reobj.findall(subject)


2. Tcl

set subject "Do you like 12 or 34?"

set result ""

set pos 0

while {[regexp -indices -start $pos -linestop {d+} $subject offsets]==1} { set pos [expr {1+[lindex $offsets 1]}] lappend result [string range $subject [lindex $offsets 0] [lindex $offsets 1]] }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读