Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有一个字符串:
“fdsfsfsfsfsdomnol$natureOrder(0123)jqnm”
我想匹配子字符串:$natureOrder(0123),我做这样的事情:
regcomp(®, "\$natureOrder\([0-9]{1,4}\)", cflags);
但它不起作用!如何编写正则表达式模式?
除了转义$,你需要在你的正则表达式中有括号,这些也必须被转义。
$
所以正则表达式将是
\$natureOrder\([0-9]{1,4}\)
当在 C 字符串中时,因为\是转义序列的开始:
\
regcomp(®, "\\$natureOrder\\([0-9]{1,4}\\)", cflags);