regexoracle-databaseplsqlfqdn

Validate FQDN Name without negative lookahead


I have found this link(www.regextester.com/103452) to validate the based on REGEX.

(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)

But there's one problem, Oracle doesn't recognize Positive/Negative Lookahead.

The first positive lookahead (?=^.{4,253}$) is easy, I can just verify the length of the string, but for the negative lookahead (?!-) I'm having some trouble figuring it out.


Solution

  • The ((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+ means 1 or more repetitions of:

    Rephrasing: there can be 1 to 63 letters, digits or - with no - as first or last char of the sequence before ..

    Use ([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+ instead, it will match 1 or more repetitions of:

    So, it matches again 1 to 63 chars with no - at the start or end of the digit-letter-hyphen sequence.