javascript - 使用正则表达式抓取 url iframe 字符串
问题描述
细绳
let iframe = "<iframe src=\"https://player.vimeo.com/video/111111\" width=\"500\" height=\"281\" frameborder=\"0\" allowfullscreen></iframe>";
我需要的是 src url 字符串。
我已经尝试了一种可以得到大部分内容的表达方式。
let url = iframe.match(/\bhttps?:\/\/\S+);
这返回
'https://player.vimeo.com/video/111111\"'
它返回了我不想要的最后的 \ 和 "。我尝试使用类似的东西
[^\"]
说“不要包括 \ 或”,但我没有做对。
正则表达式对我来说总是一个熊。
解决方案
请试试这个
let iframe = "<iframe src=\"https://player.vimeo.com/video/111111\" width=\"500\" height=\"281\" frameborder=\"0\" allowfullscreen></iframe>";
console.log(iframe.match('(?<=src=").*?(?=[\?"])'));
推荐阅读
- java - JTable 中的复选框在 Windows LookAndFeel 中不打印
- javascript - JavaScript点击不适用于InnerHtml
- mysql - 无法用laravel(docker)连接mysql
- api - TeamCity API 获取最常失败的测试列表
- javascript - lambda 函数中的 SQL 查询语法错误
- python - 使用 Python 进行正向回溯中的量词
- python - python中的日期格式不一致
- lua - Wireshark LUA 解析器 - 组合来自 2 个 UDP 数据包的数据,显示问题
- javascript - 检查时差是否超过48小时
- amazon-web-services - 调用 PutBucketVersioning 操作时发生错误(AccessDenied):此操作只能由存储桶所有者执行