在本主题中,想法是“剥离”数字,除以x
通过正则表达式。 ->如何使用 Excel 正则表达式从字符串中提取广告尺寸 https://stackoverflow.com/questions/48427343/how-to-extract-ad-sizes-from-a-string-with-excel-regex/48428045?noredirect=1#comment83851284_48428045
因此来自:
uni3uios3_300x250_ASDF.html
我想通过RegEx实现:
300x250
我已经成功地实现了完全相反的目标,并且我正在努力一段时间才能完成需要完成的事情。
这是我到目前为止所拥有的:
Public Function regExSampler(s As String) As String
Dim regEx As Object
Dim inputMatches As Object
Dim regExString As String
Set regEx = CreateObject("VBScript.RegExp")
With regEx
.Pattern = "(([0-9]+)x([0-9]+))"
.IgnoreCase = True
.Global = True
Set inputMatches = .Execute(s)
If regEx.test(s) Then
regExSampler = .Replace(s, vbNullString)
Else
regExSampler = s
End If
End With
End Function
Public Sub TestMe()
Debug.Print regExSampler("uni3uios3_300x250_ASDF.html")
Debug.Print regExSampler("uni3uios3_34300x25_ASDF.html")
Debug.Print regExSampler("uni3uios3_8x4_ASDF.html")
End Sub
如果你跑TestMe
,你会得到:
uni3uios3__ASDF.html
uni3uios3__ASDF.html
uni3uios3__ASDF.html
这正是我想通过正则表达式删除的内容。
改变IF
阻止到
If regEx.test(s) Then
regExSampler = InputMatches(0)
Else
regExSampler = s
End If
你的结果将会返回
300x250
34300x25
8x4
这是因为InputMatches
保存结果RegEx
执行,它保存您要匹配的模式。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)