我在Regex方面不强,我想写一个公式,禁止使用重复的句点和下划线输入。例如,不应允许以下内容:
Student
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
public class Student {
public String name { get; set; }
public String id { get; set; }
public Int32 status { get; set; }
public override String ToString() {
return name + "(" + id + "): " + status.ToString();
}
}
public class StudentSchedule {
public IList<Student> morning { get; set; }
public IList<Student> afternoon { get; set; }
}
public class Program
{
public static void Main()
{
String myJson = @"{
'morning':
[
{
'name': 'Morning Student 1',
'id': '123456',
'status': '0'
}
],
'afternoon':
[
{
'name': 'Afternoon Student 1',
'id': '123456',
'status': '0'
}
]
}";
StudentSchedule studentSchedule = JsonConvert.DeserializeObject<StudentSchedule>(myJson);
Console.WriteLine("========== MORNING ===========");
foreach(Student student in studentSchedule.morning) {
Console.WriteLine(student);
}
Console.WriteLine("========== AFTERNOON ===========");
foreach(Student student in studentSchedule.afternoon) {
Console.WriteLine(student);
}
}
}
h..ello
__world
一个句号或下划线不能分别在另一个句号或下划线之前或之后。
没关系,只要它们像这样混合在一起即可:
hel.....lo
(这是一个有效的字符串)
world____
(这是一个有效的字符串)