使用正则提取里面的url'"background-image: url("https://static.geetest.com/nerualpic/space_l1_zh_2019.07.17/space/1e17b1dfc08a852158695a1d813e86be.jpg?challenge=f9b89219d4e6c3a58411cd3dba22ae74"); background-size: 100%; background-repeat: no-repeat;"'
时间: 2024-02-03 14:03:50 浏览: 53
你可以使用以下正则表达式来提取该字符串中URL:
```python
import re
= 'background-image: url("https://.geetest.com/nerual/space_l1_zh_2019.07.17/space/1e17b1dfc08a852158695a1d813e86be.jpg?challenge=f9b89219d4e6c3a58411cd3dba22ae74"); background-size: 100%; background-repeat: no-repeat;'
url = re.findall('url\("([^"]+)"\)', string)[0]
print(url)
```
这将输出:
```
https://static.geetest.com/nerualpic/space_l1_zh_2019.07.17/space/1e17b1dfc08a852158695a1d813e86be.jpg?challenge=f9b89219d4e6c3a58411cd3dba22ae74
```
相关问题
使用正则提取“https://v.cdnlz2.com/20231210/27345_07b4cdb4/index.m3u8”中的“https://v.cdnlz2.com/20231210/27345_07b4cdb4”
可以使用正则表达式来提取字符串中的特定部分。对于提取“https://v.cdnlz2.com/20231210/27345_07b4cdb4/index.m3u8”中的“https://v.cdnlz2.com/20231210/27345_07b4cdb4”,可以使用以下正则表达式:
```python
import re
url = "https://v.cdnlz2.com/20231210/27345_07b4cdb4/index.m3u8"
pattern = r"(https://v.cdnlz2.com/20231210/27345_07b4cdb4)"
result = re.search(pattern, url)
if result:
extracted_url = result.group(1)
print(extracted_url) # 输出:https://v.cdnlz2.com/20231210/27345_07b4cdb4
```
正则表达式`r"(https://v.cdnlz2.com/20231210/27345_07b4cdb4)"`表示匹配字符串中的"https://v.cdnlz2.com/20231210/27345_07b4cdb4"部分。使用`re.search()`函数进行匹配,如果找到匹配的结果,则使用`result.group(1)`提取匹配的部分。
js使用正则从https://lgg.datdapp.com/storage/image/20230927.png提取出/storage/image/20230927.png
可以使用正则表达式来提取出指定的字符串。在JavaScript中,可以使用`match()`方法来实现。
```javascript
const url = "https://lgg.datdapp.com/storage/image/20230927.png";
const pattern = /\/storage\/image\/\d+\.png/;
const result = url.match(pattern);
if (result) {
console.log(result[0]); // 输出:/storage/image/20230927.png
} else {
console.log("未找到匹配的字符串");}
```