[英]Remove word and surrounding line breaks
I have a string that is a set of paragraphs.我有一个字符串,它是一组段落。
"text text text text text
TRIGGER_WORD
text text text text text"
I would like to remove TRIGGER_WORD and the line break above it, so you will end with this:我想删除 TRIGGER_WORD 及其上方的换行符,因此您将以此结尾:
"text text text text text
text text text text text"
I need to remove the line break above the "TRIGGER_WORD" to ensure there is a single space between the two surrounding paragraphs.我需要删除“TRIGGER_WORD”上方的换行符,以确保两个周围段落之间有一个空格。
So far I'm doing this:到目前为止,我正在这样做:
string.replace("TRIGGER_WORD", '')
But that does not remove the line break但这并没有删除换行符
Help?帮助?
Match as many space characters as you can after the word:在单词后匹配尽可能多的空格字符:
const input = `text text text text text TRIGGER_WORD text text text text text`; console.log( input.replace(/TRIGGER_WORD\s+/, '') );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.