I want to match everything except “eps1@“ within this string:
HelpMe_pleas3_eps1@
I tried [^eps1@]
but this matched everything except every instance of “e” “p” “s” “1” “@“. I just want “eps1@“ excluded.
I want to match everything except “eps1@“ within this string:
HelpMe_pleas3_eps1@
I tried [^eps1@]
but this matched everything except every instance of “e” “p” “s” “1” “@“. I just want “eps1@“ excluded.
There are many ways of doing it, depending on what you really need.
Using (.*)eps1@
you match everything before "eps1@" in the first capturing group. See demo #1.
Using (.*)eps1@(.*)
you match everything before and after "eps1@" in the first and second capturing groups. See demo #2.
If "eps1@" occurs multiple times, you can use this regex:
(?:[^eps1@]|e(?!ps1@)|(?<!e)p(?!s1@)|(?<!ep)s(?!1@)|(?<!eps)1(?!@)|(?<!eps1)@)+
That means:
[^eps1@]
any character but "e", "p", "s", "1", and "@"; ORe(?!ps1@)
the character "e" if not followed by "ps1@"; OR(?<!e)p(?!s1@)
the character "p" if not preceded by "e" and not followed by "s1@"; ORSee demo #3.
But have you considered just replacing "eps1@" with "" into your source string?
P.S. For the next questions I'd suggest you to be more precise on the language you're using.