鱼C论坛

 找回密码
 立即注册
查看: 1343|回复: 2

[已解决]re不会用

[复制链接]
发表于 2021-3-28 10:39:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
<script>;var chapterImages = ["\/UploadFiles\/9805\/2016516354383.jpg","\/UploadFiles\/9805\/2016516354389.jpg","\/UploadFiles\/9805\/2016516354610.jpg","\/UploadFiles\/9805\/2016516355407.jpg","\/UploadFiles\/9805\/2016516356374.jpg","\/UploadFiles\/9805\/2016516357502.jpg","\/UploadFiles\/9805\/2016516357280.jpg","\/UploadFiles\/9805\/2016516358302.jpg","\/UploadFiles\/9805\/2016516359662.jpg","\/UploadFiles\/9805\/201651640180.jpg","\/UploadFiles\/9805\/201651640851.jpg","\/UploadFiles\/9805\/201651641984.jpg","\/UploadFiles\/9805\/201651642783.jpg","\/UploadFiles\/9805\/201651643139.jpg","\/UploadFiles\/9805\/201651644320.jpg","\/UploadFiles\/9805\/201651645795.jpg","\/UploadFiles\/9805\/201651645798.jpg","\/UploadFiles\/9805\/201651646595.jpg","\/UploadFiles\/9805\/201651646696.jpg","\/UploadFiles\/9805\/201651647616.jpg","\/UploadFiles\/9805\/201651647381.jpg","\/UploadFiles\/9805\/201651648121.jpg","\/UploadFiles\/9805\/201651649249.jpg","\/UploadFiles\/9805\/2016516410732.jpg","\/UploadFiles\/9805\/2016516411302.jpg","\/UploadFiles\/9805\/2016516411868.jpg","\/UploadFiles\/9805\/2016516412715.jpg","\/UploadFiles\/9805\/2016516412141.jpg","\/UploadFiles\/9805\/2016516413846.jpg","\/UploadFiles\/9805\/2016516414979.jpg","\/UploadFiles\/9805\/2016516415661.jpg","\/UploadFiles\/9805\/2016516417536.jpg","\/UploadFiles\/9805\/2016516418439.jpg","\/UploadFiles\/9805\/2016516420326.jpg","\/UploadFiles\/9805\/2016516421689.jpg","\/UploadFiles\/9805\/2016516421563.jpg","\/UploadFiles\/9805\/2016516422817.jpg","\/UploadFiles\/9805\/2016516423274.jpg","\/UploadFiles\/9805\/2016516423149.jpg","\/UploadFiles\/9805\/2016516424127.jpg","\/UploadFiles\/9805\/2016516424912.jpg","\/UploadFiles\/9805\/2016516425372.jpg","\/UploadFiles\/9805\/2016516425813.jpg","\/UploadFiles\/9805\/2016516426169.jpg","\/UploadFiles\/9805\/2016516426388.jpg","\/UploadFiles\/9805\/2016516427746.jpg"];var chapterPath = "";</script>


有以上代码,我虽然能匹配出来,但是没能达到我的要求
我的要求是:我只要列表里面的的东西
比如:list[0] = "\/UploadFiles\/9805\/2016516354383.jpg"
以此类推
求各位大佬解答
最佳答案
2021-3-28 10:53:56
本帖最后由 suchocolate 于 2021-3-28 11:07 编辑

第一种思路:整体获取转成列表。
import re

txt = '''<script>;var chapterImages = ["\/UploadFiles\/9805\/2016516354383.jpg","\/UploadFiles\/9805\/2016516354389.jpg","\/UploadFiles\/9805\/2016516354610.jpg","\/UploadFiles\/9805\/2016516355407.jpg","\/UploadFiles\/9805\/2016516356374.jpg","\/UploadFiles\/9805\/2016516357502.jpg","\/UploadFiles\/9805\/2016516357280.jpg","\/UploadFiles\/9805\/2016516358302.jpg","\/UploadFiles\/9805\/2016516359662.jpg","\/UploadFiles\/9805\/201651640180.jpg","\/UploadFiles\/9805\/201651640851.jpg","\/UploadFiles\/9805\/201651641984.jpg","\/UploadFiles\/9805\/201651642783.jpg","\/UploadFiles\/9805\/201651643139.jpg","\/UploadFiles\/9805\/201651644320.jpg","\/UploadFiles\/9805\/201651645795.jpg","\/UploadFiles\/9805\/201651645798.jpg","\/UploadFiles\/9805\/201651646595.jpg","\/UploadFiles\/9805\/201651646696.jpg","\/UploadFiles\/9805\/201651647616.jpg","\/UploadFiles\/9805\/201651647381.jpg","\/UploadFiles\/9805\/201651648121.jpg","\/UploadFiles\/9805\/201651649249.jpg","\/UploadFiles\/9805\/2016516410732.jpg","\/UploadFiles\/9805\/2016516411302.jpg","\/UploadFiles\/9805\/2016516411868.jpg","\/UploadFiles\/9805\/2016516412715.jpg","\/UploadFiles\/9805\/2016516412141.jpg","\/UploadFiles\/9805\/2016516413846.jpg","\/UploadFiles\/9805\/2016516414979.jpg","\/UploadFiles\/9805\/2016516415661.jpg","\/UploadFiles\/9805\/2016516417536.jpg","\/UploadFiles\/9805\/2016516418439.jpg","\/UploadFiles\/9805\/2016516420326.jpg","\/UploadFiles\/9805\/2016516421689.jpg","\/UploadFiles\/9805\/2016516421563.jpg","\/UploadFiles\/9805\/2016516422817.jpg","\/UploadFiles\/9805\/2016516423274.jpg","\/UploadFiles\/9805\/2016516423149.jpg","\/UploadFiles\/9805\/2016516424127.jpg","\/UploadFiles\/9805\/2016516424912.jpg","\/UploadFiles\/9805\/2016516425372.jpg","\/UploadFiles\/9805\/2016516425813.jpg","\/UploadFiles\/9805\/2016516426169.jpg","\/UploadFiles\/9805\/2016516426388.jpg","\/UploadFiles\/9805\/2016516427746.jpg"];var chapterPath = "";</script>'''
result = re.findall(r'\[.*?\]', txt)  # 获取方括号和其中的内容,.*?非贪婪模糊匹配。
result = eval(result[0])   # 以字符串作为命令执行,相当于直接用字符串创建列表。
for item in result:
    print(item)

第二种思路:逐个jpg匹配,每jpg特点是.jpg结尾,外层有双引号。
result = re.findall(r'"(.*?\.jpg)"', txt)   # 非贪婪模糊匹配,以.jpg结尾,且外层有双引号的内容,()只打印组内的内容,外部的其他内容,包括双引号不打印。
for item in result:
    print(item)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-3-28 10:53:56 | 显示全部楼层    本楼为最佳答案   
本帖最后由 suchocolate 于 2021-3-28 11:07 编辑

第一种思路:整体获取转成列表。
import re

txt = '''<script>;var chapterImages = ["\/UploadFiles\/9805\/2016516354383.jpg","\/UploadFiles\/9805\/2016516354389.jpg","\/UploadFiles\/9805\/2016516354610.jpg","\/UploadFiles\/9805\/2016516355407.jpg","\/UploadFiles\/9805\/2016516356374.jpg","\/UploadFiles\/9805\/2016516357502.jpg","\/UploadFiles\/9805\/2016516357280.jpg","\/UploadFiles\/9805\/2016516358302.jpg","\/UploadFiles\/9805\/2016516359662.jpg","\/UploadFiles\/9805\/201651640180.jpg","\/UploadFiles\/9805\/201651640851.jpg","\/UploadFiles\/9805\/201651641984.jpg","\/UploadFiles\/9805\/201651642783.jpg","\/UploadFiles\/9805\/201651643139.jpg","\/UploadFiles\/9805\/201651644320.jpg","\/UploadFiles\/9805\/201651645795.jpg","\/UploadFiles\/9805\/201651645798.jpg","\/UploadFiles\/9805\/201651646595.jpg","\/UploadFiles\/9805\/201651646696.jpg","\/UploadFiles\/9805\/201651647616.jpg","\/UploadFiles\/9805\/201651647381.jpg","\/UploadFiles\/9805\/201651648121.jpg","\/UploadFiles\/9805\/201651649249.jpg","\/UploadFiles\/9805\/2016516410732.jpg","\/UploadFiles\/9805\/2016516411302.jpg","\/UploadFiles\/9805\/2016516411868.jpg","\/UploadFiles\/9805\/2016516412715.jpg","\/UploadFiles\/9805\/2016516412141.jpg","\/UploadFiles\/9805\/2016516413846.jpg","\/UploadFiles\/9805\/2016516414979.jpg","\/UploadFiles\/9805\/2016516415661.jpg","\/UploadFiles\/9805\/2016516417536.jpg","\/UploadFiles\/9805\/2016516418439.jpg","\/UploadFiles\/9805\/2016516420326.jpg","\/UploadFiles\/9805\/2016516421689.jpg","\/UploadFiles\/9805\/2016516421563.jpg","\/UploadFiles\/9805\/2016516422817.jpg","\/UploadFiles\/9805\/2016516423274.jpg","\/UploadFiles\/9805\/2016516423149.jpg","\/UploadFiles\/9805\/2016516424127.jpg","\/UploadFiles\/9805\/2016516424912.jpg","\/UploadFiles\/9805\/2016516425372.jpg","\/UploadFiles\/9805\/2016516425813.jpg","\/UploadFiles\/9805\/2016516426169.jpg","\/UploadFiles\/9805\/2016516426388.jpg","\/UploadFiles\/9805\/2016516427746.jpg"];var chapterPath = "";</script>'''
result = re.findall(r'\[.*?\]', txt)  # 获取方括号和其中的内容,.*?非贪婪模糊匹配。
result = eval(result[0])   # 以字符串作为命令执行,相当于直接用字符串创建列表。
for item in result:
    print(item)

第二种思路:逐个jpg匹配,每jpg特点是.jpg结尾,外层有双引号。
result = re.findall(r'"(.*?\.jpg)"', txt)   # 非贪婪模糊匹配,以.jpg结尾,且外层有双引号的内容,()只打印组内的内容,外部的其他内容,包括双引号不打印。
for item in result:
    print(item)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2021-3-28 13:13:17 | 显示全部楼层
suchocolate 发表于 2021-3-28 10:53
第一种思路:整体获取转成列表。

谢谢
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-16 04:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表