I'm trying to create a regex in JS that will match a text at the end of the string composed by an "@" symbol followed by some characters (anything that's not a whitespace character or another "@").
Here are some examples of some expected behaviors I'm looking for:
| String | Match | Group 1 |
|---|---|---|
| test | No match | - |
| @test | @test | test |
| @test aux | No match | - |
| @test @aux | @aux | aux |
| @test @@aux | No match | - |
| @test @@@aux | @aux | aux |
| @test @@@@aux | No match | - |
| @test @@@@@aux | @aux | aux |
The current regex I have - /(?<!@(?:@@)*)@([^\s@]*)$/ - doesn't work in the last use cases, when more than 3 "@" characters are used. It's supposed to find a match only if an odd number of "@" characters are used.
I would appreciate if someone could help me out with this, thanks.