【发布时间】:2016-12-02 18:02:30
【问题描述】:
这是在 C# 中。到目前为止,我一直在窃窃私语,但运气不佳。
例如
123456BVC --> 123456BVC (keep the same)
123456BV --> 123456 (remove trailing letters)
12345V -- > 12345V (keep the same)
12345 --> 12345 (keep the same)
ABC123AB --> ABC123 (remove trailing letters)
它可以从任何东西开始。
我试过@".*[a-zA-Z]{2}$",但没有成功
这是在 C# 中,所以我总是返回一个字符串,如果它们确实存在并且前面没有另一个字母,则删除两个尾随字母。
Match result = Regex.Match(mystring, pattern);
return result.Value;
【问题讨论】:
-
“AB”的输出应该是什么?
-
@dotctor:这似乎无关紧要,因为可以在运行正则表达式之前使用
mystring.Length检查字符串长度。