I want to find a link like https://stackoverflow.com/questions/37543724/python-regex-for-finding-all-words-in-a-string
in a big string but there are many links and I want all links that starts with https://stackoverflow.com/questions/
the string look like
something https://stackoverflow.com/questions/37543724/python-regex-for-finding-all-words-in-a-string
something
So my question is how can i find an uncompletet string?
Advertisement
Answer
Try this:
JavaScript
x
14
14
1
import re
2
3
def Find(string):
4
5
# findall() has been used
6
# with valid conditions for urls in string
7
regex = r"(?i)b((?:https?://|wwwd{0,3}[.]|[a-z0-9.-]+[.][a-z]{2,4}/)(?:[^s()<>]+|(([^s()<>]+|(([^s()<>]+)))*))+(?:(([^s()<>]+|(([^s()<>]+)))*)|[^s`!()[]{};:'".,<>?«»“”‘’]))"
8
url = re.findall(regex,string)
9
return [x[0] for x in url if "stackoverflow.com/questions" in x[0]]
10
11
# Driver Code
12
string = 'content_license CC BY-SA 4.0 link https//stackoverflow.com/questions/26325943/many-threads-to-write-log-file-at-same-time-in-python title Many threads to writ'
13
print(Find(string))
14
This outputs: ['stackoverflow.com/questions/26325943/many-threads-to-write-log-file-at-same-time-in-python']
, which is what I assume you want.