gpt4 book ai didi

regex - 使用正则表达式解析文本

转载 作者:行者123 更新时间:2023-12-01 06:48:40 28 4
gpt4 key购买 nike

我有一个 .txt 格式的字典,它看起来像这样:

term 1
definition 1
definition 2

term 2
definition 1
definition 2
definition 3
etc.

定义之前总是有一个选项卡,基本上是这样的:
term 1
[tab]definition 1
[tab]definition 2
etc.

现在我需要用 <term> 包裹每个术语及其定义标签,即:
<term>
term 1
definition 1
definition 2
</term>

我试图使用正则表达式来查找具有定义的术语,但没有运气。你能帮我解决这个问题吗?

感谢您的任何建议!

最佳答案

试试这个正则表达式:

(^|\n).+(\n[ \t]+.+)*

假设 ^标记字符串的开始, \n是换行符和 .不匹配换行符。

关于regex - 使用正则表达式解析文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2218433/

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