110,549
社区成员
发帖
与我相关
我的任务
分享
//数字加空格或只有数字或只有空格都不成立
//在改下,刚少了个数字和空格也不成立
List<string> list = new List<string> { "lnt tadd2 ","aa", "lint ", " ", "222 " };
Regex reg = new Regex(@"(?i)^(?![\d\s]+$)[a-z\d\s]+$");
foreach (string s in list)
{
Console.WriteLine(reg.Match(s).Success);
}
Console.ReadLine();
List<string> list = new List<string> { "lnt tadd2", "lint ", " ", "222" };
Regex reg = new Regex(@"(?i)^(?!\d+$)(?!\s+$)[a-z\d\s]+$");
foreach (string s in list)
{
Console.WriteLine(reg.Match(s).Success);
}
Console.ReadLine();
/*
true
true
false
false
*/
List<string> list = new List<string> { "lnt tadd2", "lint", " " };
Regex reg = new Regex(@"(?i)^(?![^a-z]+$)(?!\D+$)(?!\s+$)[a-z\d\s]+$");
foreach (string s in list)
{
Console.WriteLine(reg.Match(s).Success);
}
Console.ReadLine();
/*
true
false
false
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace sxLdfang
{
class Program
{
static void Main(string[] args)
{
string html = @"how are you";
string pattern = @"(?i)(?=[^a-z]*[a-z])^[a-z0-9\s]+$";
MatchCollection mc = Regex.Matches(html, pattern);
foreach (Match m in mc)
{
Console.WriteLine(m.Value);
}
Console.ReadKey();
}
}
}
运行结果:
how are you