views:

31

answers:

1

I'm trying to add soft hyphens to break up long urls and other strings in some plain text.

function breakLines(str, num){
    if(typeof num == 'undefined' || num == null){ num = 15;}
    regex = new RegExp('(\S{'+num+'})(\S{'+num+'})','g');
    return str.replace(regex, '$1­$2');
}

It works if I use the slash notation for the replace but this function above doesn't seem to work.

+1  A: 

I didn't escape the \ next the the '\S's. Works fine now.

wizard