Many questions about regex include code blocks with language agnostic, POSIX compatible patterns, using default prettifying. (Example)

A freehand circle is best

This looks kind of ugly and is confusing, since some parts are marked as literals.

How should regex code be handled? Should syntax highlighting just be disabled for regex using lang-none? I think correct syntax highlighting could improve its readability, just by marking metacharacters and escaped metacharacters.

Including a language tag results in a different highlighting and seems superfluous when talking about POSIX regex—maybe even obstructive, since most people don't want to read questions about your . Including a language tag and using a full line of code, like String pattern = "[a-z0-9]+"; wouldn't add any valuable information. It would only get rid of the random highlights by showing the whole pattern as literal, so no advantage over disabling highlighting completely. Of course including a language tag has its advantage though and a new feature should wait, IMHO, until it is clear that a question's language tag hasn't just been forgotten.

  • 1
    Yeah. Ick. I tried several of the language hints & didn't find any that really improved matters.
    – M. Tibbits
    Aug 26, 2011 at 8:32

1 Answer 1


I think you'd need to submit a language filter to highlight.js.

There is no lang-regex there yet... but there could be if someone contributed one!


Not the answer you're looking for? Browse other questions tagged .