[a-zA-Z_:]([a-zA-Z0-9_:.])*
Would this do?
[a-zA-Z_:]([a-zA-Z0-9_:.])*
Would this do?
Do you mean XML element names? If so, no, that's too exclusive, there are lots of valid characters that that doesn't cover. More in the spec here and here:
NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] |
[#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] |
[#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] |
[#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] |
[#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 |
[#x0300-#x036F] | [#x203F-#x2040]
Name ::= NameStartChar (NameChar)*
The page for XML schemas over at regular-expressions.info gives a good regex for matching XML names:
The regular expression
\i\c*
matches an XML name like xml:schema. In other regular expression flavors, you'd have to spell this out as[_:A-Za-z][-._:A-Za-z0-9]*
. The latter regex also works with XML's regular expression flavor. It just takes more time to type in.
(The page gives a full explanation of how they work.)
EDIT:
.NET also has the method XmlConvert.VerifyName(string).
From Wikipedia:
Unicode characters in the following code point ranges are valid in XML 1.0 documents:
Unicode characters in the following code point ranges are always valid in XML 1.1 documents:
The preceding code points are contained in the following code point ranges which are only valid in certain contexts in XML 1.1 documents: