# Double delimiters in listings

Using the listings package, one can define a format for some arbitrary set of delimiters and the characters enclosed within. However, when using double delimiters, the specified format doesn't apply to the closing delimiter.

Consider the following MWE.

\documentclass{article}
\usepackage{listings}
\usepackage{upquote}
\usepackage{xcolor}
\lstset{
moredelim = [s][\color{blue}]{}{'},
}
\begin{document}
\begin{lstlisting}
macros u i
ui''
\end{lstlisting}
\end{document}


This code yields the following output:

Notice how the last closing delimiter ' is not formatted in blue. Is there a way to fix this?

Note: I used the upquote package to get the desired look of verbatim apostrophes, but if not used the problem persists.

Looks like a nesting issue. From the manual (page 24), you can add an asterisk to allow inner delimiters to be found:

\documentclass{article}
\usepackage{listings}
\usepackage{upquote}
\usepackage{xcolor}
\lstset{
moredelim = *[s][\color{blue}]{}{'},
}
\begin{document}
\begin{lstlisting}
macros u i
ui''
\end{lstlisting}
\end{document}