Link to home
Start Free TrialLog in
Avatar of MrDavidThorn
MrDavidThorn

asked on

Checking for Ascii Code using Regular Expressions in VBA

Hi Folks, Im using COM object VBScript Regular Expressions 5.5 - Currently I have the code for checking a string for a match but want to check for a ascii value instead, can this be done?
Sub Checkfile()
MsgBox (TestRegExp("is.", "isablea is1"))
End Sub
Function TestRegExp(myPattern As String, myString As String)
   'Create objects.
   Dim objRegExp As RegExp
   Dim objMatch As Match
   Dim colMatches   As MatchCollection
   Dim RetStr As String
   
   ' Create a regular expression object.
   Set objRegExp = New RegExp

   'Set the pattern by using the Pattern property.
   objRegExp.Pattern = myPattern

   ' Set Case Insensitivity.
   objRegExp.IgnoreCase = True

   'Set global applicability.
   objRegExp.Global = True
   'Test whether the String can be compared.
   If (objRegExp.Test(myString) = True) Then

   'Get the matches.
    Set colMatches = objRegExp.Execute(myString)   ' Execute search.

    For Each objMatch In colMatches   ' Iterate Matches collection.
      RetStr = RetStr & "Match found at position "
      RetStr = RetStr & objMatch.FirstIndex & ". Match Value is '"
      RetStr = RetStr & objMatch.Value & "'." & vbCrLf
    Next
   Else
    RetStr = "String Matching Failed"
   End If
   TestRegExp = RetStr
End Function

Open in new window

Avatar of HainKurt
HainKurt
Flag of Canada image

use ASC("HainKurt") function : Asc returns the ANSI character code of the first letter of the string

ASC("A") --> 65
Chr(65) --> "A"
Avatar of MrDavidThorn
MrDavidThorn

ASKER

problem with Using ASC function is the way regular expression handles the match, i.e i want to search for Ascii code 160 which is a non-breaking space, with my current code, I cant pass the "   " and I cant pass the value "160" .
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial