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

正则表达式学习-TCL

发布时间:2020-12-14 02:05:42 所属栏目:百科 来源:网络整理
导读:#a 的3、4之间有3个空格 % set a "1 a 3 4 5 aaa xx11 22 3" 1 a 3 4 5 aaa xx11 22 3 #把a用空格分开 % split $a 1 a 3 {} {} 4 5 aaa xx11 22 3 % set num [lindex [split $a] 2] 3 % set num [lindex [split $a] 3] % set num [lindex [split $a] 4] % se

#a 的3、4之间有3个空格

% set a "1 a 3 4 5
aaa xx11 22 3"
1 a 3 4 5
aaa xx11 22 3
#把a用空格分开

% split $a
1 a 3 {} {} 4 5 aaa xx11 22 3
% set num [lindex [split $a] 2]
3
% set num [lindex [split $a] 3]
% set num [lindex [split $a] 4]
% set num [lindex [split $a] 5]
4
% set num [lindex [split $a] 6]
5
% set num [lindex [split $a] 7]
aaa
%

###########

% regexp ^a b
0
% regexp ^a abc
1
% regexp $a abc
0
% regexp $a abca
0
% regexp $a abca
0
% regexp a$ abca
1
% regexp a$ abcad
0
% regexp ad$ abcad
1
% regexp ae$ abcad
0
% regexp ma abcad
0
% regexp mabcadM abcad
0

% regexp ? abcad
couldn't compile regular expression pattern: quan
% regexp [?] abcad
invalid command name "?"
%
% regexp [1-9] abcad
invalid command name "1-9"
% regexp ([1-9]} abcad
invalid command name "1-9"
[ ]用法

% regexp {[1-9]} abcad
0
% regexp {[1-9]} 3
1
% regexp {[1-9]} 8
1
% regexp {[a-e]} a
1

% regexp {[a-e]} f
0

?用法
% regexp {[a?]} a
1
% regexp {[a?]} b
0
% regexp {a?} b
1
% regexp {a?} bc
1

+用法
% regexp {[1-3]+} bc
0
% regexp {[1-3]+} 2
1
% regexp {[1-3]+} 22
1
% regexp {[1-3]+} 223
1
% regexp {[1-3]+} 2234
1
% regexp {[1-3]+} 2234
1
% regexp {[1-3]+} 4
0

资料例子

% regexp {^[0-9]+$} 510
1
% regexp {^[0-9]+$} -510
0
% regexp {([0-9]+) *([a-z]+)} "Walk 10 km"
1

-inline 选项让regexp把匹配变量返回1个数据列表。
% regexp -inline {([0-9]+) *([a-z]+)} "Walk 10 km"
{10 km} 10 km
% regexp -inline {([0-9]+) *([a-z]+)} "Walk 10 km" a b c
regexp match variables not allowed when using -inline
% regexp {([0-9]+) *([a-z]+)} "Walk 10 km" a b c
1
% puts "$a,$b,$c"
10 km,10,km

-all

Causes the regular expression to be matched as many times as possible in the string,returning the total number of matches found. If this is specified with match variables,they will contain information for the last match only. % regexp -all {[0-7]} wrong # args: should be "regexp ?switches? exp string ?ma bMatchVar ...?" % set string abc123a abc123a % regexp -all {[0-7]} $string 3 % set string2 ab3c123a ab3c123a % regexp -all {[0-7]} $string2 4

(编辑:李大同)

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

    推荐文章
      热点阅读