Amechi
Amechi

Reputation: 800

Regex capture all dot characters excluding the dot character in front of '.com' in an email

Looking to do the following with regex using this email: [email protected]

In addition:

The final result would look like: [email protected]

Upvotes: 0

Views: 91

Answers (1)

vs97
vs97

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$)

enter image description here

Regex Demo

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.

enter image description here

Upvotes: 4

Related Questions