Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @John Smith says hello
- John smith says hello OR simply 'John Smith' - Either is okay for this purpose
- I was talking to @John Smith and he told me all about @Sarah Smith
- Sarah Smith
- txt.substring(txt.lastIndexOf('@')+1).split(' ').slice(0, 2).join(' ')
- var a = "@tony @stark"
- > undefined
- var b = a.lastIndexOf('@')
- > undefined
- a.substr(b, a.length)
- > "@stark"
- a.substr(b+1, a.length)
- > "stark"
- function getRest(a) {
- var b = a.lastIndexOf('@');
- return a.substr(b+1, a.length);
- }
- getRest('@John Smith says hello')
- > "John Smith says hello"
- getRest('I was talking to @John Smith and he told me all about @Sarah Smith')
- > "Sarah Smith"
- var regex = /@(w+ w+)[^@]*$/,
- myString = "@spork and @abe lincoln spam spam spam",
- match = myString.match(regex)[1];
- // match == "abe lincoln"
Add Comment
Please, Sign In to add comment