2009-08-07 5 views
2
Dim strPattern As String: strPattern = "[^a-zA-Z0-9]" 
Dim regex As New RegExp 
regex.Pattern = strPattern 
result = regex.Replace(pFileNameWithoutExtension, "_") 

작동하지만 1 문자 만 바꿉니다. 하나 이상의 문자를 어떻게 대체 할 수 있습니까? 예 : "ÉPÉ"는 "P"이어야하지만 현재 결과는 "_PÉ"입니까?VB6 Regex Replace

답변

9

전체 패턴 일치를 사용하면됩니다.

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

regex.Global = True 

regex.Pattern = strPattern 
result = regex.Replace(pFileNameWithoutExtension, "_") 
+0

+1 그리고 받아들입니다. 그 글로벌 자산에 대해 몰랐습니다. –

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

VB6에서 작동하지 않습니다. # P #가 아니라 # P #를 반환합니다. –

+0

@Gordon : 목록에없는 0 개 이상의 문자로 구성된 문자열과 일치합니다. 목록의 첫 번째 문자로 끝납니다. – MyItchyChin