我似乎无法弄清楚这一点。我需要以下内容来吐出市场价值"
Function removeScenarioTags (strtoclean)
Dim objRegExp, outputStr
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = " ?\([0-9a-zA-Z ]+\) ?"
Set objMatch = objRegExp.Execute( strtoclean )
corrected_row = strtoclean
For Each myMatch in objMatch
matched_value = myMatch.Value
corrected_row = replace(corrected_row, matched_value, "")
Next
removeScenarioTags = corrected_row
End Function
'----------------MAIN------------------------------------------
after_clean = removeScenarioTags("Market Value (steep+50)")
msgbox after_clean
答案 0 :(得分:2)
答案 1 :(得分:2)
您可以使用与括号匹配的正则表达式与括号内的任何字符匹配来简化基于正则表达式的替换,并用0+空格括起来,并直接用RegExp.Replace
方法删除匹配:
Function removeScenarioTags(strtoclean)
Dim objRegExp, outputStr
Set objRegExp = New Regexp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "\s*\([^()]+\)\s*"
removeScenarioTags = objRegExp.Replace(strtoclean, "")
End Function
请参阅\s*\([^()]+\)\s*
正则表达式演示。
<强>详情
\s*
- 0+ whitespaces \(
- (
[^()]+
- 1个或更多(替换为*
以匹配0个或更多)除(
和)
以外的字符\)
- )
\s*
- 0+ whitespaces 请注意,使用此正则表达式时,objRegExp.IgnoreCase = True
不会执行任何有意义的操作,并且可以删除。