Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用regexp在tcl中搜索backslack_Tcl_Regexp Replace - Fatal编程技术网

使用regexp在tcl中搜索backslack

使用regexp在tcl中搜索backslack,tcl,regexp-replace,Tcl,Regexp Replace,如何使用regexp在tcl中搜索反斜杠“\”。我试着跟着 regexp {\\} "b\a" regexp {\\\\} "b\a" 我想在“.”和“\”之间搜索文本。如何做到这一点?如: abcd.efg\.hij=>efg,为此我尝试了以下方法: regexp {\.[a-z]*\\.} "abcd.efg\.hij" X 如果在双引号中使用单反斜杠,那么它就没有任何特殊意义。它应该逃脱 % set input "abcd.efg\.hij"; # Check the return v

如何使用regexp在tcl中搜索反斜杠“\”。我试着跟着

regexp {\\} "b\a"
regexp {\\\\} "b\a"
我想在“.”和“\”之间搜索文本。如何做到这一点?如: abcd.efg\.hij=>efg,为此我尝试了以下方法:

regexp {\.[a-z]*\\.} "abcd.efg\.hij" X

如果在双引号中使用单反斜杠,那么它就没有任何特殊意义。它应该逃脱

% set input "abcd.efg\.hij"; # Check the return value, it does not have backslash in it
abcd.efg.hij
%
% set user "din\esh"; # Check the return value
dinesh
%
% set input "abcd.efg\\.hij"; # Escaped the backslash. Check the return value
abcd.efg\.hij
%
% set input {abcd.efg\.hij}; # Or you have to brace the string
abcd.efg\.hij
%
因此,您的regexp应该更新为

% regexp "\\\\" "b\\a"
1
% regexp {\\} "b\\a"
1
% regexp {\\} {b\a}
1
% regexp {\\} {b\\a}
1
%
要提取所需的数据

% set input {abcd.efg\.hij}
abcd.efg\.hij
%  regexp {\.(.*)?\\} $input ignore match
1
% set match
efg

如果在双引号中使用单反斜杠,那么它就没有任何特殊意义。它应该逃脱

% set input "abcd.efg\.hij"; # Check the return value, it does not have backslash in it
abcd.efg.hij
%
% set user "din\esh"; # Check the return value
dinesh
%
% set input "abcd.efg\\.hij"; # Escaped the backslash. Check the return value
abcd.efg\.hij
%
% set input {abcd.efg\.hij}; # Or you have to brace the string
abcd.efg\.hij
%
因此,您的regexp应该更新为

% regexp "\\\\" "b\\a"
1
% regexp {\\} "b\\a"
1
% regexp {\\} {b\a}
1
% regexp {\\} {b\\a}
1
%
要提取所需的数据

% set input {abcd.efg\.hij}
abcd.efg\.hij
%  regexp {\.(.*)?\\} $input ignore match
1
% set match
efg
我会使用
\.([^\\.]+)\\\.
,但这取决于其他可能的示例

模式匹配一个转义点
\.
,然后括号中的表达式
([^\\.]+)
将提取
efg
(它表示:非
[^
反斜杠
\
或点
\.
一次或多次
]+
),然后是显式反斜杠
\\
和点
.

如果使用带括号的表达式,您的模式也可以工作。此表达式捕获的匹配将放入第二个变量:

regexp {\.([a-z]*)\\.} {abcd.efg\.hij} matchVar subMatchVar
您还必须考虑到双引号字符串
“abcd.efg\.hij”
中的反斜杠已被解释器替换-最终字符串将变为
abcd.efg.hij
,从而有效地防止模式识别它。所以这里我用了大括号,或者可以用一个变量来表示这个字符串


看一看。我偶尔使用它。

我会使用
\.([^\\.]+)\\\.
但这取决于其他可能的示例

模式匹配一个转义点
\.
,然后括号中的表达式
([^\\.]+)
将提取
efg
(它表示:非
[^
反斜杠
\
或点
\.
一次或多次
]+
),然后是显式反斜杠
\\
和点
.

如果使用带括号的表达式,您的模式也可以工作。此表达式捕获的匹配将放入第二个变量:

regexp {\.([a-z]*)\\.} {abcd.efg\.hij} matchVar subMatchVar
您还必须考虑到双引号字符串
“abcd.efg\.hij”
中的反斜杠已被解释器替换-最终字符串将变为
abcd.efg.hij
,从而有效地防止模式识别它。所以这里我用了大括号,或者可以用一个变量来表示这个字符串


看一看。我偶尔用它