• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

wbr every 5 characters in really long string

New Here ,
Apr 06, 2011 Apr 06, 2011

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

TOPICS
Advanced techniques

Views

713

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Apr 06, 2011 Apr 06, 2011

But you're so close!

<cfoutput>#reReplaceNoCase("abcdefghijklmnopqrstuvwxyz", '(.{5})', '\1 ', 'all')#</cfoutput>

O.

Votes

Translate

Translate
Guide ,
Apr 06, 2011 Apr 06, 2011

Copy link to clipboard

Copied

But you're so close!

<cfoutput>#reReplaceNoCase("abcdefghijklmnopqrstuvwxyz", '(.{5})', '\1 ', 'all')#</cfoutput>

O.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2011 Apr 07, 2011

Copy link to clipboard

Copied

Thanks a ton!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2011 Apr 07, 2011

Copy link to clipboard

Copied

LATEST

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:

really_long_word.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation