Reputation: 800
Looking to do the following with regex using this email: [email protected]
.
characters excluding the .
that's in front of .com
In addition:
+
up to but not including the @
characterThe final result would look like: [email protected]
Upvotes: 0
Views: 91
Reputation: 5859
As I understand your approach was to remove the matched parts from the string in order to receive the final result. You would then need to do this in two steps (with two regex) - remove the dots, and remove the part between +
and @
.
Regex to capture all .
except before .com
: \.(?!com$)
Regex to capture everything from +
up to not including the @
character: \+[^@]*
You can use these together as a single regex expression: \+[^@]*|\.(?!com$)
Bonus
Alternatively, another approach would be to tackle this through groups, e.g:
^([^\.]+)(.)([^+]+)([^@]+)(\S+)$
You can then build the final result by combining several groups together.
Upvotes: 4