re = /(?:(?:http|https):\/\/)?(?:www.|m.)?facebook.com\/(?!home.php)(?:(?:\w)*#!\/)?(?:pages\/)?(?:[?\w\-]*\/)?(?:profile.php\?id=(?=\d.*))?([\w\.-]+)/m
str = 'http://www.facebook.com/jquery2dotnet
http://www.facebook.com/some.user
https://www.facebook.com/#!/my_page_id
http://www.facebook.com/pages/test
http://www.facebook.com/pages/test/123
https://www.facebook.com/#!/page_with_1_number
http://www.facebook.com/bounce_page#!/pages/test-Url/12345
https://www.facebook.com/bounce_page#!/my_page_id?v=app_1123325
https://www.facebook.com/notes/hyperarts-web-design
http://www.facebook.com/test.username
https://www.fb.me/jquery2dotnet
http://www.facebook.com/
http://m.facebook.com/home.php
http://m.facebook.com/test.username
https://mbasic.facebook.com/home.php?_rdr'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html