【发布时间】:2021-12-24 01:48:39
【问题描述】:
所以我的字符串如下:
TESTA:C:/Users/mycode/dir_a/./result_a/out_stra.bin;C:/Users/mycode/dir_b/./result_b/out_strb.bin;C:/Users/mycode/dir_c/./result_c/out_strc.bin
TESTB:C:/Users/mycode/dir_a/./result_a/out_stra.bin;C:/Users/mycode/dir_b/./result_b/out_strb.bin;C:/Users/mycode/dir_c/./result_c/out_strc.bin
TESTC:C:/Users/mycode/dir_a/./result_a/out_stra.bin;C:/Users/mycode/dir_b/./result_b/out_strb.bin;C:/Users/mycode/dir_c/./result_c/out_strc.bin
我需要的输出是:
TESTA:out_stra.bin;out_strb.bin;out_strc.bin
TESTB:out_stra.bin;out_strb.bin;out_strc.bin
TESTC:out_stra.bin;out_strb.bin;out_strc.bin
我尝试使用字符串正则表达式,但没有得到所需的输出。这是我尝试过的:
string(REGEX REPLACE "C:/Users/mycode/.*/\./.*/"
"" TEMP
<inputfilecontent>)
将不胜感激。谢谢。
【问题讨论】:
-
尝试
[A-Z]:(/([^/;]+))+并替换为\\2。不确定您的情况是否正确,可能是string(REGEX REPLACE "[A-Z]:(/([^/;]+))+" "\\2" TEMP ${inputfilecontent}) -
嗨@WiktorStribiżew 感谢您的建议,它只给了我最后一个 bin 并忽略了之前的其他 bin 文件
-
奇怪,好像值之间没有
;。也许路径中没有空格?试试[A-Z]:(/([^/; \t\n]+))+ -
@deb:在 Stack Overflow 上,作者完全允许修改问题以添加有关问题的信息。因此,与其删除您的old question 并询问新的相同问题,不如编辑旧的。
-
非常感谢@WiktorStribiżew 最后一个建议对我解析具有相似路径字符串的多行有很大帮助(我已经基于此修改了问题),但我仍然为每一行得到一个bin,所以用“;”分隔的“.bin”没有以某种方式连接
标签: regex cmake cmake-language