I am working on a small app where I need to remove the starting and ending
tags and I am having a little trouble getting the expression right.
Currently I have this bit of code. The issue is on the second output, nothing is displayed.
<cfcontent reset="true"/>
<cfset myStr = '<br> <br> <br> <br> This is a great Test<br> do you like my test? <br><br><br>'>
<cfoutput>#myStr#</cfoutput>
<cfset myNewString = REReplaceNoCase(myStr, '(^<.*?>+)|(<.*?>+$)', '' ,'ALL')>
<cfoutput>New: #myNewString#</cfoutput>
The following regex worked for me:
It removed the first and last tag if that’s what you wanted.
However, the
+after the closing angle bracket suggests that you maybe meant to remove all tags at the start or end; although in the current form it would match one or more closing angle brackets. You need to use groups to change that behavior:This removes all tags at the start or end of the string.