根据我对RE的理解
- > *表示匹配0或更多次出现的正则表达式
- > +表示匹配1次或多次出现的正则表达式
现在让我们看看以下示例
第一:-
% regexp {:+} "DHCP:Enabled" first
1
% puts $first
: --> ":" is stored in variable first
%
Run Code Online (Sandbox Code Playgroud)
第二:-
% regexp {:*} "DHCP:Enabled" sec
1
% puts $sec
--> Nothing is stored in variable second
%
Run Code Online (Sandbox Code Playgroud)
为什么":"存储为第一个而不是第二个?
第二个正则表达式{:*}匹配空字符串,因为空字符串是0次出现:.如果您使用该-indices选项regexp,您将看到它与位置0匹配.
% regexp -indices :* "DHCP:Enabled" indices
1
% puts $indices
0 -1
Run Code Online (Sandbox Code Playgroud)
换句话说,正则表达式匹配第一个字符并返回.