观山有月
发表于 2022-1-16 10:41:40
正则不会,用power query硬解出来,不过去除符号还没好的想法,只能用穷举
山城袍哥
发表于 2022-1-16 20:30:15
非常感谢大佬
还有几个小问题,比如:泉芯家乡花生汤圆400g会成 泉芯家乡花生汤圆g400
艾可思奖杯鸭太空杯500ML SFC-616 会成 艾可思奖杯鸭太空杯6500ml sfc61
这个可不可以再优化一下呢,如果碰到有数字与英文的时候,就按原来的顺序提取可以吗!
麻春宝
发表于 2022-1-19 13:35:26
Sub 正则替换()
r = Cells(Rows.Count, 2).End(xlUp).Row
ar = Range("B2").Resize(r, 2)
Set reg = CreateObject("VBScript.RegExp")
reg.Global = True
reg.Pattern = "[^\w一-龥 \*]+"
For i = 1 To r - 1
ar(i, 1) = reg.Replace(LCase(ar(i, 1)), "")
Next
reg.Pattern = "^(\W*)(\w[\w\* 包袋盒支片]*)([\d\D]*)$"
For i = 1 To r - 1
ar(i, 2) = reg.Replace(ar(i, 1), "$2")
ar(i, 1) = reg.Replace(ar(i, 1), "$1$3$2")
Next
Range("L2").Resize(r, 2) = ar
End Sub
閉船長
发表于 2022-1-21 19:56:42
太完美了,多想要的效果,
打伞的蜗牛
发表于 2022-1-22 21:26:26
\d+\w+(\s)?(\s)?(\w+)?-?(\d+)?(\*\d+[包袋]?)?(\*\d+[包袋]?)?
深山哥
发表于 2022-1-23 01:01:32
Sub RegExp()
Dim RegExp, i%, Match
For i = 2 To Range("B" & Rows.Count).End(xlUp).Row
Set RegExp = CreateObject("vbscript.regexp")
RegExp.Pattern = "\d+\w+(\s)?(\s)?(\w+)?-?(\d+)?(\*\d+[包袋]?)?(\*\d+[包袋]?)?"
RegExp.Global = True
Cells(i, 4) = LCase(RegExp.Execute(Cells(i, 2))(0))
Cells(i, 5) = LCase(RegExp.Replace(Cells(i, 2), "$1") & RegExp.Execute(Cells(i, 2))(0))
Next i
End Sub
森林小巷少年与狼
发表于 2022-1-24 00:05:32
=LOWER(REPLACEB(B2,SEARCHB("?",B2),2*LEN(B2)-LENB(B2),"")&MIDB(B2,SEARCHB("?",B2),2*LEN(B2)-LENB(B2)))
渭原车夫
发表于 2022-1-25 02:23:24
非常感谢大佬,
青鹏晓运
发表于 2022-2-4 16:42:14
Sub 正则替换()
r = Cells(Rows.Count, 2).End(xlUp).Row
ar = Range("B2").Resize(r, 2)
Set reg = CreateObject("VBScript.RegExp")
reg.Global = True
reg.Pattern = "[^\w一-龥 *]+"
For i = 1 To r
ar(i, 1) = LCase(reg.Replace(ar(i, 1), ""))
Next
reg.Pattern = "^([\d\D]*?)(\w[^一-龥]+)([\d\D]+)$"
For i = 1 To r - 1
ar(i, 2) = reg.Replace(ar(i, 1), "$2")
ar(i, 1) = reg.Replace(ar(i, 1), "$1$3$2")
Next
'Range("B2").Resize(r, 2) = ar
Range("L2").Resize(r, 2) = ar '为对照,把处理结果写入L列,不覆盖原数据
End Sub
即墨晓航
发表于 2022-2-7 09:34:08
正则不会,用power query硬解出来,不过去除符号还没好的想法,只能用穷举