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.
我正在寻找一种方法来从表达式中删除最后一个字符,如果它使用正则表达式超过 4 个字符
例如
187 6 31673 9667 11857 07
处理后应如下所示:
187 6 3167 9667 1185 07
你为什么要使用正则表达式而不是这样的东西?
var output = (input.Length <= 4) ? input : input.SubString(0, input.Length - 1);
如果您必须使用正则表达式,这个应该可以完成这项工作。
^(.{0,4})$|^(.+)(?:.)$