Is there any way to use the listings package (which I already use for Python) to highlight regexes? I.e. the regex appears in the document as if it were source code, but with some form of differentiation between (for example) literals and character classes, escaped control characters and real control characters.

It's not an uncommon feature in online regex testing tools.

For what it's worth, the regexes being discussed in my document are to be used for find/replace on LaTeX code, and will appear as \lstinlines.

EDIT background colour seems common for this:

  • Regexbuddy

regexbuddy screenshot

Sublime text apparently does character-colour highlighting:

Sublime text screenshot

This would seem to be (i) subjectively nicest, and (ii) most compatible with existing listings.

For reference https://www.debuggex.com/ has a nice visual parser which goes much further than anything (i) I had considered, and (ii) that would be possible in a text-based framework.

closed as unclear what you're asking by jub0bs, user13907, moewe, Svend Tveskæg, Mensch Aug 30 '14 at 12:06

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    An example with some code? An image with the output you would like (may be a print from a webpage)? – Manuel Aug 28 '14 at 10:27
  • @Manuel I'm looking for one that does it nicely - regexpal.com for example uses background colour which isn't great, and IMO doesn't do that too well. – Chris H Aug 28 '14 at 10:31
  • Well, that, and an exemplary code, should definetly be in the question. Leaving the least possible work for the people who is going to answer. – Manuel Aug 28 '14 at 10:40
  • @Manuel, I can't disagree, and I'm on the case (it's not a good google search given the uses of regexes in syntax highlighting), but I doubt anyone's going to write anything from scratch here, and if they've already written some personal code that they don't mind sharing, they won't need an example. – Chris H Aug 28 '14 at 10:42
  • 3
    @ChrisH Also some code in the question is welcome, so that, in case one wants to answer, doesn't need to write it himself (even if it's only two lines, it's better if you provide it). By the way, look at minted, pygmentex, pythontex and family; they let you use Pygments library in TeX. – Manuel Aug 28 '14 at 11:07

Browse other questions tagged or ask your own question.