Guest User

Untitled

a guest
Jan 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. @John Smith says hello
  2.  
  3. John smith says hello OR simply 'John Smith' - Either is okay for this purpose
  4.  
  5. I was talking to @John Smith and he told me all about @Sarah Smith
  6.  
  7. Sarah Smith
  8.  
  9. txt.substring(txt.lastIndexOf('@')+1).split(' ').slice(0, 2).join(' ')
  10.  
  11. var a = "@tony @stark"
  12. > undefined
  13. var b = a.lastIndexOf('@')
  14. > undefined
  15. a.substr(b, a.length)
  16. > "@stark"
  17.  
  18. a.substr(b+1, a.length)
  19. > "stark"
  20.  
  21. function getRest(a) {
  22. var b = a.lastIndexOf('@');
  23. return a.substr(b+1, a.length);
  24. }
  25. getRest('@John Smith says hello')
  26. > "John Smith says hello"
  27. getRest('I was talking to @John Smith and he told me all about @Sarah Smith')
  28. > "Sarah Smith"
  29.  
  30. var regex = /@(w+ w+)[^@]*$/,
  31. myString = "@spork and @abe lincoln spam spam spam",
  32. match = myString.match(regex)[1];
  33. // match == "abe lincoln"
Add Comment
Please, Sign In to add comment