C#正则表达式匹配字符串末尾的数字

前端之家收集整理的这篇文章主要介绍了C#正则表达式匹配字符串末尾的数字前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个以_ [一个数字]结尾的字符串. _1 _12等

我正在寻找一个正则表达式来拉出这个数字

解决方法

尝试这个: @H_301_8@(\d+)$

这是一个如何使用它的例子:

@H_301_8@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); } }

猜你在找的C#相关文章