I am trying to get a regex string working, i have been playing around for a few days and seem to be hitting the lovely fu wall.
I need a way to stop the regex from matching after @username
my Regex string looks like this (app plex) ?(?:@(.*)|)
so say the input was app plex @zycore look at this
, the output would be:
Match 1
Full match 0-16 `app plex @zycore`
Group 1. n/a `app plex`
Group 2. n/a `zycore look at this`
what i am trying to do is have it so only zycore is in group 2 and not the text after it, (the @ symbol is removed as it is not needed in the code but is needed in the application running it), it also needs to work with just app plex
as an input.
i have tried multiple variations and nothing seems to work, i am using regex101.com to test the strings. any help would be appreciated.
i have tried
(app plex) ?(?:@(.*)|)
(app plex) ?(?:@(.*)|)[\s]
(app plex) ?(?:@(.*)[\s]|)
You may use
(app plex) ?(?:@(\S*))?
See the regex demo
Details
(app plex)
- Group 1: app plex
substring ?
- an optional space(?:@(\S*))?
- an optional non-capturing group matchin 1 or 0 occurrences of
@
- a @
char(\S*)
- Group 2: 0+ non-whitespace chars.