我正在尋找在列表中使用正則表達式的可能性。我想突出顯示每個 N,後面跟著 4 個十進制數字,例如 N1234。我怎樣才能做到這一點?
這是一個例子:
\documentclass{report}
\usepackage{listings,xcolor}
\lstdefinelanguage{NCSyntax}
{morekeywords={N\d\d\d\d}, % <-- regular expression ???
sensitive=false,
morecomment=[l]{;},
morestring=[b]",
}
\lstnewenvironment{mylang}{\lstset{language=NCSyntax, keywordstyle=\color{red}\bfseries\underbar }}{}
\begin{document}
\begin{mylang}
N1234 ; colored as keyword
A1234 ; text
N12 ; text
N12345 ; text
N4242 ; colored as keyword
\end{mylang}
\end{document}