使用TCL将\tag{contents}替换为其内容(多个实例)

使用TCL将\tag{contents}替换为其内容(多个实例),tcl,Tcl,问题是:有一个带有标签的字符串(在LaTeX中),我需要仅使用TCL和regexps(我有TCL v8.4)将\textbf{contents}替换为contents。标记在字符串中出现多次 因此,以下是我所拥有的: 使用\textbf{cosine}而不是\textbf{sine}函数对压缩至关重要,因为事实证明,近似典型信号}需要的余弦函数更少 以下是我想要的: 使用余弦函数而不是正弦函数对压缩非常关键,因为事实证明,近似典型信号所需的余弦函数更少 我理解在regsub中,但我找不到如何做到

问题是:有一个带有标签的字符串(在LaTeX中),我需要仅使用TCL和regexps(我有TCL v8.4)将\textbf{contents}替换为contents。标记在字符串中出现多次

因此,以下是我所拥有的:

使用\textbf{cosine}而不是\textbf{sine}函数对压缩至关重要,因为事实证明,近似典型信号}需要的余弦函数更少

以下是我想要的:

使用余弦函数而不是正弦函数对压缩非常关键,因为事实证明,近似典型信号所需的余弦函数更少

我理解在regsub中,但我找不到如何做到这一点

以下是我到目前为止的情况:

set project_contents {The use of \textbf{cosine} rather than \textbf{sine} functions is critical for compression, since it turns out that \textbf{fewer cosine functions are needed to approximate a typical signal}.}

set match [ regexp -all -inline  {\\textbf\x7B([^\x7D]*)\x7D} $project_contents ]
foreach {trash needed_stuff} $match {

regsub -- {\\textbf\{$trash\}} $project_contents   $needed_stuff    project_contents
}

它查找带标记的文本(在$trash中)和不带标记的文本(在$needed\u stuff中),但不替换它们。非常感谢您的帮助。

您要查找的关键内容是RE需要位于
{
大括号
}
,并且RE中的文字反斜杠和大括号需要被反斜杠引用。您还需要在其中使用非贪婪量词,并将
-all
选项设置为
regsub

set project_contents {The use of \textbf{cosine} rather than \textbf{sine} functions is critical for compression, since it turns out that \textbf{fewer cosine functions are needed to approximate a typical signal}.}
set plain_text_contents [regsub -all {\\textbf\{(.*?)\}} $project_contents {\1}]
puts $plain_text_contents
这将产生以下输出:

The use of cosine rather than sine functions is critical for compression, since it turns out that fewer cosine functions are needed to approximate a typical signal. 使用余弦函数而不是正弦函数对于压缩是至关重要的,因为事实证明,近似典型信号所需的余弦函数更少。
这看起来像是你想要的那种东西。

哦,就是这样!多谢,多纳尔!!