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.
我想要一个只接受数字 0-9 而没有任何特殊字符或小数的正则表达式。也不应允许单个 0,但允许 0 后跟其他数字。
0*[1-9]\d*应该做的工作。 [1-9]将强制数字必须以 1-9 开头;或者如果它以 0 开头,则必须后跟 1-9 之间的数字。\d*然后允许出现任何数字,包括完整数字中的 0。
0*[1-9]\d*
[1-9]
\d*
我通常使用 boost/regex.hpp 库在 C++ 中工作。这应该很适合它。
boost::regex e("(\d*)([1-9])(\d*)");