Coldfusion RegEx to replace characters
I have the following code:
<cfset arguments.textToFormat = Replace(arguments.textToFormat, Chr(10), '<br />', "ALL") />
It replaces all instances of Chr(10) with a <br />
tag.
What I'd like to do however is afterwards, if there are more than two <br />
tags, re开发者_运维知识库place all the extra ones with empty string (i.e. remove them)
I could do this via code, but I'm sure a regex replace would be faster. Unfortunately I haven't a clue how to construct the regex.
Any help would be great - thanks.
There may be a more elegant regex, but this should do it:
rereplace( myText, '(<br />){2,}', '<br />', 'all' )
That should find all instances of 2 or more <br />
tags, and replace the whole set with a single tag.
精彩评论