查找以 "Column" 开头并以任何数字结尾的文本(例如 "100" ),两者之间没有任何内容,使用 C#



我想在字符串中找到文本(使用C#),该字符串以"列"开始,然后结束任何数字(例如" 100")。

简而言之,我想找到:

列1
第100栏
Column1000

但找不到:

column_1
_column1
列1 $

我找不到使用正则表达式的方法。

这几乎就像正则表达式一样容易。

^Columnd+$

其他没有正则的方式:

public string getColumnWithNum(string source)
{
     string tmp = source;
     if (tmp.StartsWith("Column"))
     {
          tmp.Replace("Column", "");
          UInt32 num
          if (UInt32.TryParse(tmp, out num)
          {
               return source; // matched
          }
     }
     return ""; // not matched
}

这应该有效。

相关内容

最新更新