|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2011-01-12 18:25 UTC] i at WalkinRaven dot name
 Description: ------------ PCRE 8.02 2010-03-19 I use the code below to validate domain names according to RFC 1034 3.5 http://www.rfc-editor.org/rfc/rfc1034.txt This rules is: <domain> ::=<subdomain> | " " <subdomain> ::=<label> |<subdomain> "."<label> <label> ::=<letter> [ [<ldh-str> ]<let-dig> ] <ldh-str> ::=<let-dig-hyp> |<let-dig-hyp> <ldh-str> <let-dig-hyp> ::=<let-dig> | "-" <let-dig> ::=<letter> |<digit> <letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case <digit> ::= any one of the ten digits 0 through 9 I've checked my pattern many times, and guess there may something wrong with PCRE. Test script: --------------- $domain = 'www.WalkinRaven.name'; $result = \preg_match ( '/^ (?P<label> (?P<letter>[a-z]) | # One-letter domain name (?P>letter) (?P<let_dig>[a-z 0-9]) | # Two-letters domain name (?P>letter) (?P<ldh_str>[a-z 0-9 \-]){1,61} (?P>let_dig) # More-letters domain name ) (\. (?P>label))*+ # More labels \.? # Root domain name $/Dix', $domain ); echo $result; Expected result: ---------------- 1 Actual result: -------------- 0 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 12:00:01 2025 UTC | 
No, I think this is a bug, for if you just remove all references, like changing regular expression to: /^ ( [a-z] | # One-letter domain name [a-z] [a-z 0-9] | # Two-letters domain name [a-z] ([a-z 0-9 \-]){1,61} [a-z 0-9] # More-letters domain name ) (\. ( [a-z] | # One-letter domain name [a-z] [a-z 0-9] | # Two-letters domain name [a-z] ([a-z 0-9 \-]){1,61} [a-z 0-9] # More-letters domain name ))*? # More labels \.? # Root domain name $/Dix All others are not changed, you will get the right result. P.S. in original I've written a mistake for "(\. (?P>label))*+ # More labels" should be "(\. (?P>label))*? # More labels".