numpy numpy - 9 months ago 42
Python Question

Why is this regex expression not working?

I want to separate out the links from the string which don't have ':' in between and do not end with '.jpg' or '.svg', and also start with '/wiki/'.

So these are wrong -


How the final result should look like -


What I tried -


But its not evaluating properly, infact its giving all the result which I do not want... I'm kind of new to regex, so please tell me why this is not working, and how should I correct it.



You can try that:


The two negative lookbehinds at the end ensure that the string doesn't end with .svg or .jpg.

[^:]* avoids any : in the string.