'How to extract the substring from the beginning to a character?
I want to use Python 3 regex to extract a substring of URL from the beginning to the character ?.
input:
url = 'https://www.reuters.com/article/us-health-coronavirus-mexico-city/mexico-city-to-begin-gradual-exit-from-lockdown-on-monday-idUSKBN23K00R?feedType=RSS&feedName=worldNews'
expected output:
'https://www.reuters.com/article/us-health-coronavirus-mexico-city/mexico-city-to-begin-gradual-exit-from-lockdown-on-monday-idUSKBN23K00R'
I tried the following:
import re
end = article_urls[0].find('?')
article_urls[0][:end]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
