1

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

sorry i don't know about it. now I have ticked it. thanks again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.