VBScript String Clean

 

VBScript String Clean with Regular Expressions - Remove/Replace Characters

The following VBScript can be used to remove illegal characters from a string using regular expressions.  The following characters are removed from the string in the example below: (?*",\<>&#~%{}+_.@:\ /!;

These characters are illegal in file names of documents in SharePoint Document Libraries.

1. Instantiate a new Regular Expression Object:
Dim objRegExp, outputStr
Set objRegExp = New Regexp

2. Configure the object:
objRegExp.IgnoreCase = True
objRegExp.Global = True

3. Set the search pattern for the Regular Expression Object:
objRegExp.Pattern = "[(?*"",\<>&#~%{}+_.@:\/!;]+"

4. Call the Replace method to remove or replace characters specified in the search pattern:
outputStr = objRegExp.Replace(strtoclean, "-")

 

More:

View Full Article