【发布时间】:2014-05-14 13:57:10
【问题描述】:
这是我的 html 文件:
<head>
<title>Reading from text files</title>
</head>
<body>
<h3>Starting space</h3>
<ul>
<li></li>
</ul>
<h3>ending space</h3>
<ul>
</body>
</html>
我想使用 tcl 和正则表达式来编辑这个 html 文件。但我想在特定位置编辑它,即在Starting space 和ending space 之间。在这些点之间,我想添加各种列表项。
<li> First </li>
etc.. 我编写了 tcl 脚本来打开这个文件,并尝试打印出这两个位置之间的数据,以便我以后可以编辑它。但我无法做到这一点。你能指出我哪里出错了吗?
Tcl 脚本
proc edit_html {release} {
set fp [open $release r]
set para [read -nonewline $fp]
close $fp
set line_read [regexp -nocase -lineanchor -inline -all -- {^\s*?Starting space\s*?.*?ending space} $para]
foreach line_read $line_read {
regexp -nocase -- {^\s*?Starting space\s*?.*?ending space} $line_read - tag value
puts $value
}
}
edit_html [lindex $argv 0]
我不确定这个正则表达式哪里出错了。一旦我找到位置,我应该如何编辑它?有什么提示吗?就像我应该带文件指针一样?
【问题讨论】: