正则表达式TCL使用程序
我是一名TCL程序员新手。我来了 - 我在 stackoverflow 论坛上发表的第一篇文章。
我想编写一个匹配任何 & 的正则表达式只有字符串以字符 A 开头并以 B 结尾。无论中间的字符是什么,都应该显示。例如 AXIOMB 作为用户的输入,以 A & 开头。以字符 B 结尾。
这是我的尝试,
regexp { (^A([C-Z]+)B$)}
谢谢
I am a novice TCL programmer. Here I go - My 1st post with stackoverflow forum.
I would like to write a regular expression that matches any & only the strings starts with character A and ends with B. Whatever the characters coming inbetween should be displayed. For instance AXIOMB as an input from the user which starts with A & end with character B.
Here is my try
regexp { (^A([C-Z]+)B$)}
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你非常接近:(
->
实际上是一个不寻常的变量名称。但在这里我使用该符号,因为它看起来比使用其他等效的someRandomDummyVariable
:-))如果您想从命令行或控制台获取要测试的字符串,请按以下方法操作:
命令行参数(不带 Tcl 解释器或脚本的名称)以列表形式显示在全局 argv 列表变量。第一个是
[lindex $::argv 0]
。可以通过 gets 命令从控制台读取一行。
请注意,与 C 中不同的是,Tcl 中的
gets
可以有效防止缓冲区溢出,并且scanf()
的(几乎)全部功能大约相当于scan [获取标准输入] ...
(出于安全原因排除的某些格式除外)。You're very close:
(The
->
is actually an unusual variable name. But here I'm using that symbol because it looks better than using the otherwise-equivalentsomeRandomDummyVariable
. :-))If you're seeking to get the string to test from the command line or the console, here's how:
Command line arguments (without the name of the Tcl interpreter or the script) are presented as a list in the global
argv
list variable. The first one is thus[lindex $::argv 0]
.A line can be read from the console via the
gets
command.Note that, unlike in C,
gets
in Tcl is strongly defended against buffer overflows and the (almost) full power ofscanf()
is about equivalent toscan [gets stdin] ...
(except for some formats excluded for security reasons).