英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论