0

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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.