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]*d[0-9]+(\+[0-9]*)*$'
以以下格式限制输入
str1 = '3d8+10' str2 = 'd8+2+4'
但是,我也让下面的字符串通过:
str3 = 'd8++2'
有没有办法编写正则表达式以将模式限制为 +X+X+X...?
你需要
^[0-9]*d[0-9]+(\+[0-9]+)*$ a * here ^ allows only + to match as well
如果字符串必须至少有一个,则在末尾+ n使用(一个或多个)+
+ n
+
^[0-9]*d[0-9]+(\+[0-9]+)+$
看来您正在寻找
'^[0-9]*d[0-9]+(\+[0-9]+)*$'