3
Dim strPattern As String: strPattern = "[^a-zA-Z0-9]" 
Dim regex As New RegExp
regex.Pattern = strPattern
result = regex.Replace(pFileNameWithoutExtension, "_")

It does work but it replace only 1 char. How can I replace more than one char. Example : "ÉPÉ" should be "P" but currently the result is : "_PÉ"?

2 Answers 2

9

You just need to enable global pattern matching.

Dim strPattern As String: strPattern = "[^a-zA-Z0-9]" 
Dim regex As New RegExp

regex.Global = True

regex.Pattern = strPattern
result = regex.Replace(pFileNameWithoutExtension, "_")
Sign up to request clarification or add additional context in comments.

Comments

0
Dim strPattern As String: strPattern = "[^a-zA-Z0-9]*" 
Dim regex As New RegExp
regex.Pattern = strPattern
result = regex.Replace(pFileNameWithoutExtension, "_")

1 Comment

@Gordon: that just matches a string of 0 or more characters not in the list, it terminates at the first character in the list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.