![列表中的正则表达式](https://linux22.com/image/266110/%E5%88%97%E8%A1%A8%E4%B8%AD%E7%9A%84%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F.png)
我正在寻找在列表中使用正则表达式的可能性。我想突出显示每个后跟 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}