1、需求内容
处理电商搜索词,对于同一个词用户可能有多种写法,比如:
iphone 11 case
case iphone 11
ip11 case
case ip11 beatiful
i phone 11 case
vivo y20i phone case(这类i phone不做替换)
为了方便后续数据统计,在数据预处理的时候,将ip 、 i phone、ipone均替换为" iphone "
使用的方案为:正则表达式匹配和替换,但是发现被替换的词位于开头位置时,不能替换。如图红色标明的字段

字段说明:
搜索提示词:用户最初搜索的词
手机信号:4G/5G
分类(无实意词):for,with等词
品牌[原]:用户搜索词中实际输入的部分,如:ip,ipone
品牌:数据统计时需要的品牌,如:iphone
正则表达式调用方式:正则表达式存在Excel中,通过循环调用

(aaaaa|iphone|\bi phone|ipone)|ip(?=\d)
(aaaaa|realme|real me|realmie|realmi|real mi|real\b)
尝试过的方案:
1、上图的正则表达式本来是没有aaaaa部分的,对于字符串iphone 11 case,最开始用
(iphone|\bi phone|ipone)|ip(?=\d)无法匹配出iphone,加上aaaaa这部分后,可以匹配
然后睡了个午觉
2、基于1做品牌realme,再次执行程序后,iphone和realme均无法匹配开头的字符串
iphone xr case
xr case
redmi phone case
v11i phone case
ip11 case aesthetic
case ip11
case for ip11
case i phone
v11 ipone case
case iphone xr
realme note 50 case
realmi c51 phone case
real c65 case