Regex gets domain name from email

I learn regular expressions and cannot receive googlefrom email address

line

first.name@google.com

I just want to get Google, not Google.com

Regex:

[^@].+(?=\.)

Result: https://regex101.com/r/wA5eX5/1

From my understanding. This ignores @finding the line after this until .(dot) using(?=\.)

What have I done wrong?

+12
source share
7 answers

[^@]means "match a single character that is not familiar @. This is not what you are looking for - use lookbehind (?<=@)for @and your (?=\.)lookahead for \.to extract the server name in the middle:

(?<=@)[^.]+(?=\.)

[^.]+ " ".

Demo.

+9

:
:)

@(\w+)

,
( )
\w [A-Za-z0-9_]
+ \w

Regex Regex101

+5

regex , , : foo@us.industries.com, foobar@tm.valves.net foo@ge.test.com

, , ( ), :

(?<=@)[^.]*.[^.]*(?=\.)
+3

:

(?<=@)[^.]+

(?<=@) - @ [^.]+ - , ( )

, google .

+2

, " ", ( , @ "first.last" ) cut:

cut -d @ -f 2 | cut -d . -f 1 

@, - , . : xxxx@server.com/xxx.yyy.zzz @server.com ..

+2

, @ (,.com,.org). , , .

>>> regex = re.compile(r"^.+@(.+)\.[\w]+$")

>>> regex.findall('jane.doe@my-bank.no')
['my-bank']

>>> regex.findall('john.doe@spam.com')
['spam']

>>> regex.findall('jane.ann.doe@sandnes.district.gov')
['sandnes.district']
0

, , , :

  • ( .com.ar co.jp)

, test@ext.domain.com.mx domain.com.mx

, :

[^.@]*?\.\w{2,}$|[^.@]*?\.com?\.\w{2}$

regex101 : https://regex101.com/r/vE8rP9/59

You can get the name sumdomain (without a top-level domain, for example: .comor .com.mx) by adding search operators (but it will match twice in test@test.com.mx):

[^.@]*?(?=\.\w{2,}$)|[^.@]*?(?=\.com?\.\w{2}$)

0
source

Source: https://habr.com/ru/post/1651714/


All Articles