I have successfully used this Regex to match "example.com" from your list of test cases.
"(?<hostname>(\w+\.)*)(?<domainname>(\w+\.\w+))"
The dot character (".") Must be escaped as "\.". "." a character in a regular expression pattern matches any character.
1 , ( "(? (\ w +)).". , ). "example.com", .
, "1 , ". "foo" "foo.example.com" "foo.bar" "foo.bar.example.com".