0

I'm learning regular expressions and I'm having trouble extracting the domain from the email address. I have an email address: example@gmail.com. I need to use a regular expression to extract @gmail (along with the @ symbol). I should end up only getting example. I've already tried this:

your text@(\w+) and this your text(?<=@)[^.]+(?=.).* but those expressions didn't work properly. I'd appreciate your help.

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • you can found the response here https://stackoverflow.com/a/39027263/8081292 – Henock Dec 30 '22 at 12:00
  • 1
    Does this answer your question? [Regex get domain name from email](https://stackoverflow.com/questions/39027204/regex-get-domain-name-from-email) – ljmc Dec 30 '22 at 12:06

1 Answers1

0

I just tried a simple look behind - @(?<=@).* it will match @google.com you can also group the entire expression and can change it according to single and multi-line matches.

@(?<=@).*

enter image description here

Vikka
  • 159
  • 3
  • Please do not answer questions which are obvious duplicates with accepted answers. – ljmc Dec 30 '22 at 14:28
  • @ljmc - thank you for the information, I did not realize that tbh. also if it is a duplicate question then this should be closed no? – Vikka Dec 30 '22 at 18:19
  • I have flagged it as duplicate as you can see from my comment. Feel free to flag as well, and hopefully it gets reviewed soon and closed. – ljmc Dec 30 '22 at 19:27