I'm looking for a way to extract LinkedIn profile pages from lists of URLs using Ruby. Currently I am looping over the URLs and matching them against this regex:
/^http:\/\/.+\.linkedin.com\/(pub|in)/
However, the URLs of LinkedIn profile directory pages are as follows:
http://www.linkedin.com/pub/dir
, so I'm looking to avoid any links that have the pub/dir path in them. I know it's possible to negate character classes in Ruby regexs, such as [^abc] matching any character that isn't abc. Is there a way to do the same with strings? I.e. matching any sequence of characters besides "dir"?
You can use a negative lookahead. Something like
(pub(?!\/dir)|in)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With