In Ruby I have a regex to get a string formatted like "@xxx":
(/(?<!\S)@[A-Za-z0-9\-]+/)
I also need this regex on the client side, but JavaScript can't read this.
How can I change this regex to JavaScript?
Well you don't have lookbehind in JavaScript regular expression so you can't use (?<!\S) in a JavaScript regex.
You can use:
/(?:^|\s)(@[A-Za-z0-9-]+)/
And use captured group #1 for your matched text.
Alternatively you can use XRegExp library in JS and use the lookbehind feature.