Scooter Daraf Scooter Daraf - 6 months ago 10
Javascript Question

Get sentence without a word after special character

How can i have the whole sentence without the first word which is preceded by special character ?

for example if i have this sentence:

@jonson where are you?


i want get just this

where are you?


and if its like that

where are you @jonson ?


i want get

where are you?


i know how to get the word after
@
like that :

var moo = "@jonson where are you?".match(/@([^ ]*)/)[1]; // jonson


hope it can be done , because i need to get that sentence.
thanks

Answer

you can use string replace:

 var moo = "@jonson where are you?".replace(/@\w*/,'');

document.write(moo)

you're matching the @ character
followed by any word-character( \w ) , in any quantity ( * );