Skip to content

Instantly share code, notes, and snippets.

@ndthanh
Created June 4, 2017 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndthanh/8d8516b8c187beac527fe2a272c610c7 to your computer and use it in GitHub Desktop.
Save ndthanh/8d8516b8c187beac527fe2a272c610c7 to your computer and use it in GitHub Desktop.
Public Function lay_so(s As String) As String
Dim s2 As String
Dim replace_hyphen As String
replace_hyphen = " "
Set re = CreateObject("vbscript.regexp")
If re Is Nothing Then Set re = CreateObject("vbscript.regexp")
re.IgnoreCase = True
re.Global = True
re.Pattern = "[^0-9 -]" 'includes space, if you want to exclude space "[^0-9]"
s2 = re.Replace(s, vbNullString)
re.Pattern = "[^0-9 ]"
lay_so = re.Replace(s2, replace_hyphen)
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment