Copy link to clipboard
Copied
I have some users put in really long strings in a text area and when it's displayed the formatting is thrown off because there are no spaces. To fix this I want to insert a wbr every 5 spaces that gives the browser the option to break if it needs to. I have it working in javascript and a version working in coldfusion, but the coldfusion version inserts the wbr every other character. Any idea how to insert a wbr every 5 characters with a REReplace()?
Thanks!
GP
javascript:
<script type="text/javascript" language="JavaScript">
str = '#really_long_text#';
str = str.replace(/(.{5})/g,'$&<wbr/>');
document.write(str)
</script>
ColdFusion:
<cfset str = REReplace(really_long_text, "(.{0})", "<wbr>", "all">
again this does it every other character, but I need it every 5 characters
But you're so close!
<cfoutput>#reReplaceNoCase("abcdefghijklmnopqrstuvwxyz", '(.{5})', '\1 ', 'all')#</cfoutput>
O.
Copy link to clipboard
Copied
But you're so close!
<cfoutput>#reReplaceNoCase("abcdefghijklmnopqrstuvwxyz", '(.{5})', '\1 ', 'all')#</cfoutput>
O.
Copy link to clipboard
Copied
Thanks a ton!
Copy link to clipboard
Copied
The function works almost perfcet... but in the image below you'll see it will break a word it shouldn't if given the change. (Below, it breaks "make")
Any idea how to check if there is a space coming up in the next 7 characters and if not, put a <wbr>?
Here's the code as it's working:
<cfset notes_wbr = REReplaceNoCase("#notes#", '(.{5})', '\1<wbr>', 'all')>
But it does this to the output where "make" is broken into two words: