我正在尝试编写一个程序以识别'a*'
下的字符串程序逻辑:通过使用过渡图,我想验证状态的输入。 如果状态识别给定的模式规则。然后在不接受的* els* els Print字符串下接受打印字符串。
这就是我尝试的
Dim regex As Regex = New Regex("ba*b")
Dim match As Match = regex1.Match(txt_input.Text)
If match.Success Then
lbl_output.Text = txt_input.Text & " is accepted under rule 'a*'"
Else
lbl_output.Text = txt_input.Text & " is not recognized"
End If
问题是当我输入字符串(如 saa )时,将接受它。它允许任何字符在字符 a 之前出现。我希望仅在字符串包含字符a时接受。例如A,AAA,AAA,
为什么不尝试以下正则言论:
^a+$
代码:
Dim regex As Regex = New Regex("^a+$")
Dim match As Match = regex.Match("aaaa")
If match.Success Then
Console.WriteLine("match")
Else
Console.WriteLine("no match")
End If
演示:
rextester
尝试以下
Dim regex As Regex = New Regex("baS*b")