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.
我需要使用正则表达式验证“+”和“-”符号,但我必须将验证放入以下字符串:
"^[A-Za-z0-9.&,@!?#%'$()/\\\\ \\-_]+$"
谁能告诉我我该怎么做?
您已经将“-”与您的正则表达式匹配。只需像这样添加'+':
"^[A-Za-z0-9.&,@!?#%'$()/\\ \-_+]+$"
(实际上"^[A-Za-z0-9.&,@!?#%'$()/\\\\ \\-_+]+$")
"^[A-Za-z0-9.&,@!?#%'$()/\\\\ \\-_+]+$"
减号已包含在您的正则表达式中。要将加号字符添加到经过验证的字符集中,只需添加它: