2

lets say I have a string

string = "Today is going well the dog jumped over the fence. The fence was 
my neighbors asdkhttps://www.urldefence.org/ult/sdfo/90nf3f/lknfksjdn? 
>>>09sdkfjnkbIAS(F89kjfs and here are some more words before another link 
lkm.http//www.someothersite.com/kasd09/3oif/3fo3/3/nffiosuf??? 
DF*SDF***8skdjnf and some more words in the end."

I want to just replace the long strings that contain the http link, defined by space before the text, and space after, with http being somewhere in the middle.

I've been trying..

re.sub('\bhttps?\b', '', string)
re.sub('https?.*?', '', string)
re.sub('https?.*?([\s+])', '', string)

having trouble connecting the dots.

4
  • How do you define when the link ends? Commented Mar 23, 2019 at 2:50
  • apologies, space at the beginning and space at the end. Commented Mar 23, 2019 at 2:50
  • 2
    So re.sub(r'https?://\S*', '', string)? Commented Mar 23, 2019 at 2:57
  • Yup, that's the one. Thank you sir. Commented Mar 23, 2019 at 2:58

1 Answer 1

1

I am not much good in regex but I tried following regex and it match the string you want with space. So you can try this if work.

http.*?([\s])
Sign up to request clarification or add additional context in comments.

3 Comments

this is close to what I want. what about everything before http as well?
It will exclude the content before http
yeah I figured out adding it anyways. but this got me close. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.