gpt4 book ai didi

tcl - 如何拉出/和之间的每个字符串;在 tcl

转载 作者:行者123 更新时间:2023-12-04 10:52:32 30 4
gpt4 key购买 nike

我有 cat/bat/d;hen/jeep/e;ink/kin/l;赋值给一个变量

set f "cat/bat/d;hen/jeep/e;ink/kin/l;"

输出应该是 d ; e ; l
我尝试将它用于:
set ff [regexp -all -inline {/.*?;} $f]

但它给
{/bat/d;} {/jeep/e;} {/kin/l;}

你们可以建议使用正则表达式的解决方案吗?

最佳答案

您将不得不使用捕获组,并防止任何 ;/在你的比赛中。在代码中,这意味着:

set ff [regexp -all -inline -- {/([^;/]+);} $f]

这目前给出(主要比赛及其捕获组):
{/d;} d {/e;} e {/l;} l

您可以使用 lmap然后只取偶数位置的元素(捕获组):
set ff [lmap {main capture} $ff {set capture}]

这使
d e l

关于tcl - 如何拉出/和之间的每个字符串;在 tcl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59408826/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com