我正在寻找在列表中使用正则表达式的可能性。我想突出显示每个后跟 4 个十进制数字的 N,例如 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}