tags:

views:

270

answers:

2
+1  Q: 

VB6 Regex Replace

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É"?

A: 
Dim strPattern As String: strPattern = "[^a-zA-Z0-9]*" 
Dim regex As New RegExp
regex.Pattern = strPattern
result = regex.Replace(pFileNameWithoutExtension, "_")
Gordon Bell
Doesn't work in VB6. It returns #PÉ and not #P#.
Daok
@Gordon: that just matches a string of 0 or more characters not in the list, it terminates at the first character in the list.
CptSkippy
+4  A: 

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, "_")
CptSkippy
+1 and accepted. Didn't know about that Global property.
Daok