Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression to extract hostname from fully qualified domain name

Tags:

regex

I am VERY rusty with regular expressions and need one to extract a hostname from a fully qualified domain name (FQDN), here's an example of what I have:

myhostname.somewhere.env.com
myotherhostname.somewhereelse.insomeotherplace.byh.info

and I want to return

myhostname
myotherhostname

Would really appreciate some help

I tried "(.+)\." but it matched the string from the right and produced:

myhostname.somewhere.env.
myotherhostname.somewhereelse.insomeotherplace.byh.
like image 678
Mark Allison Avatar asked Jul 10 '12 14:07

Mark Allison


People also ask

How do I get a fully qualified hostname?

On your Windows PC, follow these steps to find your FQDN: Launch the Control Panel by searching for "Control Panel" in the Start Menu, or by typing Win+R and typing "control.exe" in the Run menu. On the System Information screen, you will see both the hostname and FQDN of your machine.

What is the term used to specify the fully qualified domain name?

A fully qualified domain name (FQDN) is the complete domain name of a specific server or host on the Internet.

How do I know if my FQDN is valid?

The validation of FQDN object is performed using RegEx pattern ^([a-zA-Z0-9. _-])+$ by the system to determine if a given hostname uses valid characters. Where ^ specifies start of a string, and $ specifies end of a string and + indicates one or more strings in the Round Brackets. [a-zA-Z0-9.

What the fully qualified domain name you mapped?

Fully Qualified Domain Name (FQDN) mapping enables the Authentication Service to take corrective action in the case where a user may have typed in an incorrect URL. This is necessary, for example, when a user specifies a partial host name or IP address to access protected resources.


1 Answers

use this regexepression (.+?)(?=\.)

like image 176
burning_LEGION Avatar answered Sep 22 '22 04:09

burning_LEGION