如何在Groovy中从特定字符串删除到段落末尾至末尾。

huangapple go评论95阅读模式
英文:

How to delete from a particular string to end to the end of the paragraph in groovy

问题

我有这一段话,开头是请随意回复此电子邮件...,我想将从这一点开始直到段落末尾的内容替换为空字符串。我已经看了以下内容,但似乎并不起作用:

replaceAll
String s = replaceAll("Feel free to reply to this email..", " ") //这并没有帮助,因为我需要知道要替换的完整文本。

您的建议将不胜感激。
英文:

I have this paragraph that starts with Feel free to reply to this email..., I want to replace everything from this point that is from Feel free to reply to this email.. to the end to the end of the paragraph with an empty string. I have taken a look at the following but it seems not to work:

replaceAll
String s = replaceAll("Feel free to reply to this email..", " ") //this was not helpful since I need to know the complete text that I want to replace.

Your suggestions will be highly appreciated.

答案1

得分: 1

你可以在 replaceFirst 中使用以下正则表达式:

(?s)随意回复此电子邮件.*

请参阅Groovy演示

(?s)随意回复此电子邮件.*模式首先匹配随意回复此电子邮件,然后.*匹配由于嵌入了(?s)标志选项而使与默认情况下不匹配的任何字符,包括换行字符。

英文:

You may use the following regex with replaceFirst:

(?s)Feel free to reply to this email.*

See the Groovy demo

The (?s)Feel free to reply to this email.* pattern matches Feel free to reply to this email first and then .* matches all the rest of the text due to (?s) embedded flag option that makes . match any char including line break chars that . does not match by default.

huangapple
  • 本文由 发表于 2020年5月4日 22:08:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/61594189.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定