• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 650
  • Last Modified:

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
    RetStr = "String Matching Failed"
   End If
   TestRegExp = RetStr
End Function

Open in new window

  • 2
1 Solution
HainKurtSr. System AnalystCommented:
use ASC("HainKurt") function : Asc returns the ANSI character code of the first letter of the string

ASC("A") --> 65
Chr(65) --> "A"
MrDavidThornAuthor Commented:
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" .
HainKurtSr. System AnalystCommented:
could not get what this mean "I cant pass the value "160""

in your pattern you can use "\xFF" or "\uFFFF" format
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now