-2

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?

  • 1
    Hello! Please read [How to ask a good question](https://stackoverflow.com/help/how-to-ask) and [How to create a minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). What specific problem are you encountering? – Brian61354270 Apr 06 '21 at 19:49

1 Answers1

0

Try this:

import re
  
def Find(string):
  
    # findall() has been used 
    # with valid conditions for urls in string
    regex = r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))"
    url = re.findall(regex,string)      
    return [x[0] for x in url if "stackoverflow.com/questions" in x[0]]
      
# Driver Code
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'
print(Find(string))

This outputs: ['stackoverflow.com/questions/26325943/many-threads-to-write-log-file-at-same-time-in-python'], which is what I assume you want.

The Pilot Dude
  • 2,091
  • 2
  • 6
  • 24