Wikipedia has several restrictions on an article's title. I summarize them here:
- It may not be empty.
- It may not begin with a lowercase letter. A character is considered lowercase if it has an
Ll
after its name in UnicodeData.txt. - It may not contain any of the characters:
# < > [ ] | { } _
- It may not be
.
or..
- It may not begin with
./
or../
. - It may not contain
/./
or/../
. - It may not end with
/.
or/..
. - It may not contain any space character (a character is considered a space if it has
Zs
after its name in UnicodeData.txt) except forU+0020 SPACE
. - It may not contain more than one consecutive space.
- It may not consist entirely of spaces.
- It may not begin with a colon.
- It may not begin with the language prefix of any of the 292 language editions of Wikipedia followed by a colon. This includes
en:
for English. - It may not begin with the prefix of another Wikimedia Foundation project or its shortcut followed by a colon.
- It may not contain the character
%
followed by two hexadecimal digits. - It may not contain a named HTML character entity. Numbered entities are already forbidden through
#
. - It must contain no more than 256 bytes when encoded in UTF-8.
Write a function that takes in a string (or whatever data type your language normally uses to manipulate text) and outputs a boolean indicating whether the string is a valid Wikipedia article title. You are permitted to use networking libraries to download and read from any page that I linked in this question.
true/false
oryes/no
? The latter will save me some bytes :p \$\endgroup\$may not contain more than one consecutive space or underscore
apply to underscore followed by space, or space followed by undescore? 2. What counts as an HTML entity? Only a finite list of them, any characters between&
and#
, or ... ? 3. No reference is given for which Unicode characters count as spaces or lowercase letters. \$\endgroup\$