Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
774 views
in Technique[技术] by (71.8m points)

regex - Regular Expressions in MS Access VBA?

I definitely like MS Access as an RAD-Tool for small-scope data-driven applications. But one thing I really miss as a .Net-Developer is Regular Expressions. They really come in handy when validating user input. I really do not know why Microsoft did not put these in the standard VBA-Library.

Is there a way to use Regular Expressions in MS Access VBA?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use the VBScript Regex Object by adding a reference to the Microsoft VBScript Regular Expressions library.

Example usage:

Dim szLine As String  
Dim regex As New RegExp  
Dim colregmatch As MatchCollection  

With regex  
   .MultiLine = False  
   .Global = True  
   .IgnoreCase = False  
End With  

szLine = "Analyzed range (from-to)  10  100"  

regex.Pattern = "^Analyzed range"  
If regex.Test(szLine) Then  
   regex.Pattern = ".*?([0-9]+).*?([0-9]+)"  
   Set colregmatch = regex.Execute(szLine)  

   'From  
    Debug.Print colregmatch.Item(0).submatches.Item(0)  
    'To  
    Debug.Print colregmatch.Item(0).submatches.Item(1)  
End If  

Source: http://mark.biek.org/blog/2009/01/regular-expressions-in-vba/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...