TCL - 使用正则表达式获取另一个字符串中由空格分隔的字符串列表
如何在 TCL 中编写匹配单词和空格的正则表达式。例如我有
aaaa bbbb cccc
并且我想匹配“aaaaa”,“bbbb”,“cccc”。 另外请告诉我空白和非空白的正则表达式符号是什么。我到处都找不到它。
谢谢。
How to write a regexp in TCL that matches word and whitespaces. For example I have
aaaa bbbb cccc
and I want to match "aaaaa ", "bbbb ", "cccc ".
And also please tell me what is the regex symbol for whitespace and non-whitespace. I can't find it anywhere.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的想法是只搜索单词字符的分组:
您可以在 re_syntax 手册页
My thought would be to just search for groupings of word characters:
You can find the writeup for the Tcl regular expression syntax on the re_syntax man page
我不太确定您想要什么,但这里有一个示例:
它会产生以下输出:
在 RE 中,
\S+
表示非空白字符的非空序列,\s+
表示非空的空白序列。我可以分别使用\w+
(“单词”字符)和\W+
(“非单词”字符)。 RE 中的括号包围捕获组; Tcl 不需要 RE 来匹配整个输入字符串。I'm not quite sure exactly what you want, but here's an example:
Which produces this output:
Within the RE,
\S+
means a non-empty sequence of non-whitespace characters and\s+
means a non-empty sequence of whitespace. I could have used\w+
(“word” chars) and\W+
(“non-word” chars) respectively. The parentheses in the RE surround capture groups; Tcl does not require REs to match the whole input string.空格的正则表达式符号是“”。就像 [az .] 给你一个空格,以及句点和小写字母。
Regex symbol for whitespace is " ". Like [a-z .] gives you a whitespace, as well as period and lowercase letters.