如何使用正则表达式从C#中的字符串中获取最后2个字符?
设置字符串-
string str = "Cookie and Session";
使用以下正则表达式从字符串中获取最后2个字符-
Regex.Match(str,@"(.{2})\s*$")以下是代码-
示例
using System;
using System.Text.RegularExpressions;
public class Demo {
public static void Main() {
string str = "Cookie and Session";
Console.WriteLine(Regex.Match(str,@"(.{2})\s*$"));
}
}输出结果
on
热门推荐
7 祝福语简短的微信
10 火把节祝福语简短
11 祝福语签名简短霸气女生
12 升班祝福语简短10字
13 牛年祝福语简短走心
14 新年顾客简短祝福语大全
15 对爱人的祝福语简短
16 生日祝福语男生韩语简短
17 孩子语音婚礼祝福语简短
18 立冬祝福语简短给女孩