rgbcof
asked on
perl, valid dns name
A valid DNS name has to be (it does not have to have .com etc.)
1. A host name (label) can start or end with a letter or a number
2. A host name (label) MUST NOT start or end with a '-' (dash)
3. A host name (label) MUST NOT consist of all numeric values
4. A host name (label) can be up to 63 characters
I am new to perl. Can you write either one or 4 separate regular expression (i prefer multiple regex)?
1. A host name (label) can start or end with a letter or a number
2. A host name (label) MUST NOT start or end with a '-' (dash)
3. A host name (label) MUST NOT consist of all numeric values
4. A host name (label) can be up to 63 characters
I am new to perl. Can you write either one or 4 separate regular expression (i prefer multiple regex)?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
santoshmotwani's example is fine. If you would rather it be separated, then this should be what you need:
[1] & [2]
^[a-zA-Z0-9].*[a-zA-Z0-9]$
[3]
^(?!\d+)$
[4]
^.{1,63}$
@jmatix
Your first pattern fails rule 2.
Your first pattern fails rule 2.
Correction to account for lowercase only:
[1] & [2]
^[a-z0-9].*[a-z0-9]$
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@kaufmed:
I am checking if it starts with an alpha-num. So there is no need to check separately that it does not start with dash(-).
I am checking if it starts with an alpha-num. So there is no need to check separately that it does not start with dash(-).
>> MUST NOT start or end with a '-' (dash)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@jmatix
Also, the bound on your "length" is from 1 to Infinity. The quantifier applies to EVERYTHING inside the parentheses.
Also, the bound on your "length" is from 1 to Infinity. The quantifier applies to EVERYTHING inside the parentheses.
NM. You caught it in the new one :)
ASKER
Gents, the solutions are great. The Regex library is a good way too, but our systems don't have that library and we can't make the udpate to all of them.
ASKER