2015-05-01 64 views

回答

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 

如果你不想和下劃線,只需取出正則表達式中的下劃線即可。

希望這有助於 查理

相關問題