gpt4 book ai didi

javascript - 用 Javascript Regex 替换不包含特定字符串的行的回车符

转载 作者:行者123 更新时间:2023-11-30 16:49:55 25 4
gpt4 key购买 nike

后面有一些文本行

Procedure Gato
Do task1
If early Then come back
turn 2
End Procedure
Schedule Balo
If late Then go to home
turn 2
End Schedule'

我需要的结果是

Procedure Gato: Do task1: If early Then come back
turn 2: End Procedure
Schedule Balo: If late Then go to home
turn 2: End Schedule'

我使用模式 \(?!\n.*(\b(Procedure |Schedule |Then )).*)\n\ 来替换所有不包含“Procedure”或“安排”或“然后”之前。但是,它仅适用于不包括“Then”的“Procedure”和“Schedule”。如何获得我需要的准确结果?很高兴收到一些建议。

最佳答案

这个模式将完成这项工作:

(^(?:(?!Then)(?! Procedure)(?! Schedule).)*)(\n\s*)

它基本上捕获了 lookAheads 上没有单词的行,并将 \n\s* 替换为空格(\s* 主要用于下一行选项卡)。我也捕获了该行的其余部分,因此替换必须是 $1:

参见 Demo

关于javascript - 用 Javascript Regex 替换不包含特定字符串的行的回车符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30683237/

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