从python上的txt文件中提取数据

2024-09-27 07:22:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要从很多文本文件中提取Insta配置文件名。 配置文件名称有一些变化,我们可以在下面看到,并且在很多文本中:

@profilename 
insta: profile_name 
Ig: profilename
IG: profilename
ig: profile.name
Instagram: @profile.name
Instagram @profilename
IG profilename
Insta: profile_name
Insta: profilename
https://instagram.com/profilename
IG @profilename
Ig: _profilename_
Instagram  : profilename
Ig profile_name
IG >> profilename
stagram: profilename
ig @ _.profile.name.__
INSTAGRAM acc: profile_name
Ig: ____profilename____
IG: @profile.name

我使用的是python,我不知道如何只获取请求的数据。 我们以前有空间 在配置文件名称之后(这是所有pn的唯一通用名称)

最好的方法是什么?你知道吗


Tags: namehttps文本名称文件名配置文件profileinstagram
1条回答
网友
1楼 · 发布于 2024-09-27 07:22:08

也许这会有帮助?你知道吗

@\S+|(?<=:\s).+|(?<=ig\s)\w+|(?<=com/).+|(?<=@\s).+|(?<=>>\s).+

Regex Demo

这包括(蛮力?)上述问题中描述的所有可能的变化。也许这不是最有效的方法,但是看看其他人的想法会很有趣。你知道吗

正则表达式解释:

@\S+          Match profilename after @
|             or
(?<=:\s).+    Match profilename after : + space
|             or
(?<=ig\s)\w+  Match profilename after ig + space OR IG + space (enable case insensitive flag -i)
|             or
(?<=com/).+   Match profilename after com/
|             or
(?<=@\s).+    Match profilename after @ + space
|             or
(?<=>>\s).+   Match profilename after >> + space

enter image description here

相关问题 更多 >

    热门问题