Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript text word wrap replace

// Static Width (Plain Regex)
const wrap = (s) => s.replace(
    /(?![^
]{1,32}$)([^
]{1,32})s/g, '$1
'
);

// Dynamic Width (Build Regex)
const wrap = (s, w) => s.replace(
    new RegExp(`(?![^
]{1,${w}}$)([^
]{1,${w}})s`, 'g'), '$1
'
);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #text #word #wrap #replace
ADD COMMENT
Topic
Name
7+9 =