I found a strong regexp, credits goes to @PhillPafford (PHP RegEx for "Website Name" If you upvote my answer, please upvote his first!):
/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/
To see it in action:
http://rubular.com/r/GOHHrucCdX
UPDATE:
This one will find the names anywhere in the text:
/(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?/
Note that I removed the ^
at the start and the $
at the end to make it work within a text:
Rubular source:
^ Start of line
$ End of line
http://rubular.com/r/iEVzfv2U3O
@GandalfStormCrow noticed that the following is matched:
Since I was little.My first dog
#^^^
The only way I see to solve this issue would be to replace little.My
with little. My
:
text.gsub(/\w\.[A-Z]/) { |matched_string| matched_string.gsub('.', '. ') }
See it in action:
1.9.3p489 :018 > text = "hello my name is robert.My dog"
=> "hello my name is robert.My dog"
1.9.3p489 :019 > text.gsub(/\w\.[A-Z]/) { |matched_string| matched_string.gsub('.', '. ') }
=> "hello my name is robert. My dog"