0

I have this regex for detecting @xxx

/(?:@)(.*[a-zA-Z0-9]*)/

it matches even when the @xxx is not separated from another string from the left (when it's typed in the middle of an input line).

xxx@xxx will match too so i added \s to require a space in the begining .Now it's

/\s(?:@)(.*[a-zA-Z0-9]*)/

But the problem is there isn't a match when the @xxx is typed in the begining of a line (the white space is still required) and i need it match in that case.

I tried to get inspired by https://stackoverflow.com/a/19973707/170592 so i added ^[^-\s] in the begining of the regex to make it

/^[^-\s](?:@)(.*[a-zA-Z0-9]*)/

But it didn't work neither.

Bardelman
  • 2,176
  • 7
  • 43
  • 70

1 Answers1

0

I think that what you are looking for it is /\S+/ which means that check for any non-whitespace and I don't think you need the ^ at the beginning.

[-\S+](?:@)(.*[a-zA-Z0-9]*)