Guest User

Untitled

a guest
Jan 23rd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. var replaceString = function(str, data, replaceWith,type) {
  2.  
  3. var boundary = "",space ="";
  4. if(type === 'hashtag') {
  5. boundary = "#"
  6. } else if(type === "mentions") {
  7. space = " ";
  8. }
  9. data = data.replace(/([.?*+^$[]\(){}|-])/g, "\$&");
  10. //return str.replace(new RegExp("(?:^|\s)("+data+")(?!\s)", 'g')," "+replaceWith);
  11. return str.replace(new RegExp("(?:^|\b|\s)(" + data + ")(?!$\b\s"+boundary+")","g")," "+replaceWith+space);
  12. };
Add Comment
Please, Sign In to add comment