VB6正则表达式替换

时间:2009-08-07 15:05:39

标签: regex vb6

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

它确实有效,但它只能替换1个字符。如何替换多个char。示例:“ÉPÉ”应为“ P ”但目前结果为:“_PÉ”?

2 个答案:

答案 0 :(得分: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, "_")

答案 1 :(得分:0)

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