Sometime ago I needed a function to remove the punctuation marks from a string in classic ASP.
The function created passed in the string to have the punctuation removed. Using regular expressions the unwanted punctuation was then removed.
The function removePunctuation used to remove punctuation marks:
Function removePunctuation(str)
Dim regEx
Set regEx = New RegExp
regEx.Global = True
' The case of characters will be ignored
regEx.IgnoreCase = True
' Remove two white space characters together
' \s matches white space
' {2,} will look for two characters together
regEx.Pattern = "\s{2,}"
str = Trim(regEx.Replace(str, " "))
' The punctuation mark characters to be removed are listed in this pattern
regEx.Pattern = "(\!|\.|\?|\;|\,|\:,|\&,|\_,|\{,|\},|\[,|\],|\(,|\),|\(,|\),|\~,|\#)"
' Return the string with the characters specified above removed.
removePunctuation = regEx.Replace(str, "")
End Function
The function should be called as:
sString = removePunctuation(wString)
Where sString in the new modified string and wString is the original string which includes the unwanted characters and white space.


