regex:取索引中的id

本文介绍了一种使用SQL查询特定日期范围内、指定频道和内容ID的曝光数据的方法,并通过Python进行正则表达式匹配来提取候选键中的ID部分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SQL

select date,content_id,rec_queue_name_,
-- w:word,到:结束,选第一个
regexp_extract(candidate_key_,'id=(\\w+):',1) as candidate_key,count(1) as exposure
from events
where date >= '2021-10-27' and date <= '2021-11-01'
and event = 'imp_detail_page'
and channel = 'ssss_popular'
and content_id = '7ebc54c538a745fcb898d08344dbf91f'
and (rec_queue_name_ = 'zili-recent-liked-eges-cold-start-exploit-queue'
or rec_queue_name_ = 'zili-recent-related-exploit-queue-v97')
group by date,content_id,rec_queue_name_,regexp_extract(candidate_key_,'id=(\\w+):',1)

python

A(.*?)B 表示截取 A/B 中间的字符串

import re
txt = 'inews_panipuri:queue:type=eges_explicit_second_coldstart_v3:when=hour:id=10e7e8fa6c5644b6b929a6b8a93f8bba:language=en:ordering=sim'
bs64_str = re.findall("id=(.*?):", txt)[0]
print(bs64_str)

def get_id(txt):
    try:
        bs64_str = re.findall("id=(.*?):", txt)[0]
    except Exception as e:
        print(e)
        print(txt)

data['id'] = data['candidate_key'].apply(lambda x:get_id(x))
data.head()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值