如何使用 Regex 从 C# 字符串中获取最后 2 个字符?
设置字符串 -
string str = "Cookie and Session";
使用以下 Regex 从字符串中获取最后 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP