VespaQQ VespaQQ - 1 year ago 54
Python Question

Regex to find links in one row

I have this string:\r

I need to extract all links in one line which ends with \r. It can contain one link or even five links. I got something like this :


but it returns whole row as one match,
any ideas ?


You can use this lookahead based regex in findall:

>>> s='\r'
>>> re.findall(r'https?://.+?(?=https?://|[\r\n]|$)', s)
['', '']

(?=http://|[\r\n]|$) is positive lookahead that asserts next position has http:// or \r or \n or line end.

RegEx Demo