I want to map url inside strings like
u1 = "Check this out http://www.cnn.com/stuff lol" u2 = "see http://www.cnn.com/stuff2" u3 = "http://www.espn.com/stuff3 is interesting"
Something like the following works, but it is cumbersome because I have to repeat the whole template
re.findall("[^ ]*.cnn.[^ ]*|[^ ]*.espn.[^ ]*", u1)
In particular, in my real code, I wanted to map a much larger number of websites. Ideally, I can do something similar to
re.findall("[^ ]*.cnn|espn.[^ ]*", u1)
but of course it doesnโt work right now because I am not correctly specifying the website name. How can this be done better? Thanks.
source share