0
我试图设计简单的编译器(扫描仪),我需要知道我可以编写代码识别标识包含例如ID45的字母和数字,并打印代码VB6.0认识标识符包含字母和数字
我试图设计简单的编译器(扫描仪),我需要知道我可以编写代码识别标识包含例如ID45的字母和数字,并打印代码VB6.0认识标识符包含字母和数字
不知道你想要什么,如果你想检查一个字符串开头字母,之后可能包含字母或数字,你可以使用普通的expressons
Function IsVar(txt as string) as Boolean
'txt ="id45"
IsVar = False
Dim re1 As String
re1 ="((?:[a-z][a-z0-9_]*))"
Dim r As New RegExp
r.Pattern = re1
r.IgnoreCase = True
bX = re.Test(sSendLine)
If bX = True Then
IsVar = True
End If
End Function
基本上常规的指令“说:”
[a-z] match a single character present in the list
a-z a single character in the range between a and z (case sensitive)
[a-z0-9_]* match a single character present in the list
a-z a single character in the range between a and z (case sensitive)
0-9 or a single character in the range between 0 and 9
_ or the character _ (underscore)
* do the previous match from zero to unlimited times (as many times as possible) [greedy]
如果我们应该有一个字符串“id45”。
the first character is an I -- first instruction successful (next)
character 2 = d -- second instruction successful (repeat)
character 3 = 4 -- second instruction successful (repeat)
character 4 = 5 -- second instruction successful (repeat)
no more characters -- return true
如果你不想和下划线,只需取出正则表达式中的下划线即可。
希望这有助于 查理
您需要向我们展示一些代码,我们可以发表评论。 – Rob