简体   繁体   中英

How do I remove a part of an URL using regex in Python?

I have an a list of URL that looks like this:

' https://www.superpopgadget.com/collections/best-sellers/products/sushi-roll-bazooka?Ffbclid=IwAR3WfVizYJF0RCP2AsSoulLjJK2_OUwQZ0Y1eep_b3Einm1XNJbcF_K3wYI '

I wanna scrape it to just get: ' https://www.superpopgadget.com/collections/best-sellers/products/sushi-roll-bazooka '

Not sure if there is any other more efficient method but this might work fine:

(.+)\?(.+)

It matches in the first group everything before the character ? and the second group is everything after it. What you need is the first group.

Example in Regex101

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM