Tcl 多线线头修剪
我有一个有多行的问题字符串:Tcl 多线线头修剪,tcl,Tcl,我有一个有多行的问题字符串: line1 Link1: //website/go/<example> line2 它的输出是: found link :<empty line> //website/go/<example> <empty line>` 如何删除所有空格、换行符等,并对其进行修剪,以获得我正在寻找的字符串部分。在这种情况下,只需获取://website/go/ 给定此输入数据: line1 Link1: //websit
line1
Link1: //website/go/<example>
line2
它的输出是:
found link :<empty line>
//website/go/<example>
<empty line>`
如何删除所有空格、换行符等,并对其进行修剪,以获得我正在寻找的字符串部分。在这种情况下,只需获取://website/go/ 给定此输入数据:
line1
Link1: //website/go/<example>
line2
但是,在这种情况下,我实际上会使用regexp来选择我想要的数据:
regexp -line {Link1:\s+(.*\S)} $output -> temp
puts "found link : $temp
正则表达式往往更适合于解析部分格式的数据,只要您记住保持它们的简短。回复的时间越长,越难理解。URL是否始终是第二行的第二个字?。是的,它始终是第二行。帖子由my tryPlease update以预期结果进行更新
set temp [string map { " " "" "line1" "" "Link1: " "" "line2" "" } $output]
set temp [string trim $temp]
puts "found link : $temp
regexp -line {Link1:\s+(.*\S)} $output -> temp
puts "found link : $temp