我有以下代码,可以从混合的英语和阿拉伯字母中提取英语字母
Sub Test()
Dim a As Variant
Dim i As Long
With Cells(1).CurrentRegion.Resize(, 3)
a = .Value
With CreateObject("VBScript.RegExp")
.Global = True
For i = 1 To UBound(a, 1)
.Pattern = "[^\w_ ]+"
a(i, 3) = Trim$(.Replace(a(i, 1), ""))
Next i
End With
.Value = a
End With
End Sub
我需要更改模式以便也能够提取数字..所以我需要提取英文字母和数字。
最佳答案
在 \w
之后添加 \d
。如果数字位于阿拉伯字母之间,则可以提取数字。
来自 @Tiw/OP 的评论。
关于regex - 使用正则表达式提取英文字母和数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53979080/