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 for U+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.

  • \$\begingroup\$ true/false or yes/no? The latter will save me some bytes :p \$\endgroup\$
    – Leaky Nun
    Commented Apr 3, 2016 at 8:34
  • 1
    \$\begingroup\$ This question needs a lot of work: it contains multiple links to required external data which is likely to change, and has several unclear requirements. \$\endgroup\$
    – feersum
    Commented Apr 3, 2016 at 8:35
  • 1
    \$\begingroup\$ For the second condition, is the Greek small letter eta (η) allowed? \$\endgroup\$
    – Leaky Nun
    Commented Apr 3, 2016 at 8:36
  • \$\begingroup\$ @feersum Please explain all of what is unclear, so I can fix it. The external data will be referenced by the revision of those pages at the moment I made this question \$\endgroup\$
    – EMBLEM
    Commented Apr 3, 2016 at 15:54
  • \$\begingroup\$ I am not going to list all that is unclear as there is too much. Here's a few questions to start with: 1. Does 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\$
    – feersum
    Commented Apr 3, 2016 at 16:03

1 Answer 1


Retina, 1221 bytes

^(?=...:|\w|(^|.*/)\.\.?(/.*|$)|.*([#<>\[\]|{}]|  |__|%[0-9a-fA-F]{2}|&#(\d{4}|[0-9a-fA-F]{4}|a(mp|pos)|(l|g|quo)t);|~~~)|[ _]*$|.{257,}).*

where ... is:


(I used this regex optimizer and manutally typed in all the data)

Try it online without the ...!

  • \$\begingroup\$ Does this test for all the lowercase letters? There are a lot more than 26 of them, there are 1984 of them according to that file. \$\endgroup\$
    – marinus
    Commented Apr 22, 2016 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.