• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 528
  • Last Modified:

Using coldfusion regex to cut a too long word

Hi, I want to cut words of more than n characters in 2 parts like n=10: nnnnnnnnnn = nnnnn- nnnnn. or nnnn- nnnnnn.
I would like to use regex for that, thanks!
  • 2
1 Solution
Right, this is completely untested:

<cfset string = "abcdefghij">

<cfset newstring = REReplaceNoCase(string, "([[:print:]]{5})([[:print:]]{5})", "\1-\2")>

Basically I'm using parentheses ( ) around two parts.  The {5} means give me exactly 5 characters.  So we're looking for a string that has 5 characters, then another 5 characters.  This regex isn't very advanced, so if your string is longer than 10 characters, the extra bits aren't taken into consideration.  

The replace part then says give me the first bit in parentheses (the first 5 characters), then a hyphen, then the second set of 5 characters.  
khristofeAuthor Commented:
That is working, but i would like to modify all words in this text that have more than 10 characters separating charcters with an hyphen after char 5 for example...
And then output the final text with all those words with hyphen after the character 5...

Loremipsum dolor sit amet, consectetur adipiscing elit. Crainsapien. Sed dapibussagittis quam. Vivamus est erat, elementumid, pulvinar id, aliquam et, metus. Proin vestibulum eros ac dui consequat porta.

khristofeAuthor Commented:
The idea was to use regex to hyphenize long words into a div with justify text on it, CSS3 allows to do that using WORD-WRAP, but CSS2 don't... is it possible to use a script for that?

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now