1

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, replace 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.

Paolo Broccardo
  • 1,942
  • 6
  • 34
  • 51
  • This was asked 16 minutes ago: http://stackoverflow.com/questions/5184396/how-can-i-remove-a-word-from-a-string-if-it-occures-more-than-1-in-a-row-with-reg – Kobi Mar 03 '11 at 18:00

1 Answers1

5

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.

charliegriefer
  • 3,342
  • 1
  • 18
  • 20