var text = "Lorem ipsum 234456234 Lorem ipsum 7345287346 asdfae"; var re = /(?=\B(?:\d{3})+(?!\d))/g alert( text.replace( re, ' ' ) );