假设*必须紧跟&。
例如,
string asd = "Mother*&Mother*&Son";
// which is "Mother+ "*&" + "Mother" + "*&" + "Son"
// This is correct string.
不好的例子
string asd = "Mother*Mother*&Son";
string asf = "Mother**&Mother*&Son";
string asg = "Mother*&*Mother*&Son";
如何在C#中检查字符串是否正确?
编辑
根据你们介绍的正则表达式的用法,我有一个附带的问题。我实际上是用逗号(,)代替星号(*),并用引号(“)代替&符号(&)。
在C#中,(让我使用其中一个例子)
Regex.IsMatch("Mother,\",Mother,\"Son", @"\,(?!")")
//won't work.. any idea?
我也试过
Regex.IsMatch("Mother,\",Mother,\"Son", @"\,(?!\")")
//not work, neither
最佳答案
通过查找任何后跟与号(*
)的星号(&
)来查找故障:
Regex.IsMatch("Mother*&*Mother*&Son", @"\*(?!&)")
关于c# - C#,检查字符串是否在“字母”后跟“字母”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19573022/