[英]How to hide text after matching and before keyword in regular expressions?
[英]How to get all the text before and after some characters using regular expressions
如何使用正则表达式从 url 中获取一些字符,例如:
如何获取/posts/之前和之后的字符aaaa和123456789 ?
import re
url = "https://www.facebook.com/aaaaaa/posts/123456789/sdd"
out = re.match('.+/(.+)/posts/(.+)/', url).groups()
print(out)
# Output:
('aaaaaa', '123456789')
url = "https://www.facebook.com/aaaaaa/posts/123456789/sdd"
得到123456789
:
url.split('/')[5]
为aaaaaa
url.split('/')[3]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.