作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
后面有一些文本行
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/
我是一名优秀的程序员,十分优秀!