如何仅使用正则表达式提取数字?

2024-09-28 23:14:03 发布

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

我有一个字符串“[123456]Filename123”,我只想得到[]中的数字

输入:[123456] Filename123,输出:['123456'],我想要123456

我的代码:

from plexapi.server import PlexServer
import re
authType = 1

def getNumbers(str):
    str = re.findall(r'[0-9].....', str)
    return str

if authType == 1:
    baseurl = 'http://localhost:32400'
    token = 'token'
    plex = PlexServer(baseurl, token)

pics = plex.library.section('Pictures')
print(pics.search())

for name in pics.search():
    print(name.title)
    print(getNumbers(name.title))

Tags: nameimportretokensearchtitleplexprint