Is there any way to get all string (include other sign like -,) before a given specific sign (in this case '@' sign)?
Example domain\username@abc I want to get "domain\username" so I use expression (.+)@ and it work.
but in same time there will be some input witch are without @abc only "domain\username" ,So it don't need to be split, (.+) will work
But can't figure out a regex expression that can match both ,
- Domain\username@abc.com return Domain\username
- Domain\username return Domain\username
IN THE SAME GROUP
My solution is make a if-else before regex expression so it can decide is string contains @ sign, so I can apply different expression for both situations.
I had tried
- Use or (|) to make end of string are @ or word boundary :(.+)(@|\b) ->it always match \b so it will not stop at '@' sign
- Make @ sign match 0 or 1 times : (.+)@{0,1} ->>I don't understand Why this not work.But it not work in regex101.com ,it will always match full string