How to remove text after certain word

那年仲夏 提交于 2020-01-30 08:15:06

问题


I have a string

The best laid schemes of mice and men

How do I remove all text after the word "schemes" in ColdFusion? I suppose this can be done with regex.


回答1:


Here ya go:

<cfset myString = "The best laid schemes of mice and men" />
<cfoutput>#REReplace(myString, "schemes(.*)", "schemes")#</cfoutput>



回答2:


Your regex is:

schemes.*$

and replace with "schemes"

Explanation

.*$ means match any character (.) 0 or more times (*) till the end of the row ($)




回答3:


Try this regex:

schemes(.*)

Replace $1 with empty string ""



来源:https://stackoverflow.com/questions/7388400/how-to-remove-text-after-certain-word

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!