匹配字符串末尾数字的C#正则表达式
我有一个以u[数字]结尾的字符串,例如1 12等 我正在寻找一个正则表达式来提取这个数字试试这个:匹配字符串末尾数字的C#正则表达式,c#,C#,我有一个以u[数字]结尾的字符串,例如1 12等 我正在寻找一个正则表达式来提取这个数字试试这个: (\d+)$ 下面是一个如何使用它的示例: using System; using System.Text.RegularExpressions; class Program { static void Main() { Regex regex = new Regex(@"(\d+)$", RegexOptions.Compiled |
(\d+)$
下面是一个如何使用它的示例:
using System;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
Regex regex = new Regex(@"(\d+)$",
RegexOptions.Compiled |
RegexOptions.CultureInvariant);
Match match = regex.Match("_1_12");
if (match.Success)
Console.WriteLine(match.Groups[1].Value);
}
}
试一试
…对于字符串的结尾(不是行),请确保未设置“多行”选项。
_(\d+)$