gpt4 book ai didi

python - 在 Pandas 中的两个字符串之间提取字符串

转载 作者:太空狗 更新时间:2023-10-30 02:08:45 26 4
gpt4 key购买 nike

我有一个文本列,如下所示:

http://start.blabla.com/landing/fb603?&mkw...

我想提取“start.blabla.com”这总是介于:

http://

和:

/landing/

即:

start.blabla.com

我愿意:

df.col.str.extract('http://*?\/landing')

但它不起作用。我做错了什么?

最佳答案

你的正则表达式匹配http:/,然后是尽可能少的0+ /符号,然后是/landing

您需要匹配并捕获 http:// 之后的字符 ( The extract method accepts a regular expression with at least one capture group. ) 而不是 /,1 次或更多次.可以用

http://([^/]+)/landing
^^^^^^^

其中 [^/]+negated character class/ 以外的字符匹配次数超过 1 次。

参见 regex demo

关于python - 在 Pandas 中的两个字符串之间提取字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41141206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com