关于正则表达式 [英] About Regex

查看:93
本文介绍了关于正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想问一下正则表达式中的字符串模式.我想验证一些字符串,例如:"IDA0230332",这是字符串",数字为8".
我已经尝试使用此代码,但是它不起作用.你能帮我吗,什么是字符串模式"最适合呢?.

我的代码:

Hi all, i wanna ask you about string pattern in regex. I want to validate some strings such as : "IDA0230332", "This is a string", "The number is 8".
I have tried using this code, but it doesn''t work. Would u help me please what "string pattern" is the best for that..??

My Code :

private static int IsContaintRegex(string temp)
{
      if (Regex.IsMatch(temp, "^[0-9]+\\s+([a-zA-z]+|[a-zA-z]+\\s+[a-zA-z]+)$", RegexOptions.IgnoreCase).Equals(true))
      {
        return 1;
      }
      else { return 0; }
}

推荐答案

",RegexOptions.IgnoreCase).等于(返回 1 ; } else {返回 0 ; } }
", RegexOptions.IgnoreCase).Equals(true)) { return 1; } else { return 0; } }


如果我理解得对:
If I understand you right:
string[] strings = { "IDA0230332", "This is a string", "The number is 8", "Hello+sd","55#5"};
          foreach (string str in strings)
          {
              Console.Write(str + "\t\t");
              string reg = @"^(\w|\s)*


"; 如果(Regex.IsMatch(str,reg)) { Console.WriteLine(" ); } 其他 {Console.WriteLine(); } }
"; if (Regex.IsMatch(str, reg)) { Console.WriteLine("match"); } else { Console.WriteLine(); } }


这篇关于关于正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆