我必须在包含特殊字符(^)的单词后面提取一行中的所有单词。从以下行:
skipping root#14^wvoice as file not exists
node wroot#15^GetBuildType already complete
预期产量:
as file does not exists
already complete
我尝试使用正则表达式,如下所示:
(?<=\^\w).*
但得到的结果是:
wvoice as file not exists
GetBuildType already complete
先谢谢你。你知道吗
我可以给你
然后使用第二个匹配的组(index=1)
解释如下:link
你可以用
或者,仅获取第一个匹配项:
参见regex demo。你知道吗
细节
\^
-匹配的是文本^
\S*
-0+非空白字符\s*
-然后是0+个空格字符(.*)
-捕获组1:除换行符(LF)之外的任何0个或更多字符。你知道吗参见Python demo:
输出:
相关问题 更多 >
编程相关推荐