Advertisement
stuppid_bot

wrap text js with regexp

Sep 5th, 2014
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function wrapText(s, w) {
  2.     w=w||78;
  3.     var re=new RegExp('(.{1,'+w+'})(?:[ \\t\\r]+|$)\\n?|(.{1,'+w+'})','g');
  4.     return s.match(re).join('\n');
  5. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement