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É”?
答案 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, "_")