Consider a URL embedded in plain text, such as http://example.com/. Stack Overflow is smart enough to know that I didn't mean to include the period at the end as part of the URL, even though .
is an unreserved character according to RFC 3986.
Likewise, if I type http://example.org/, Stack Overflow is smart enough to know that I didn't mean to include the comma, even though as a member of the sub-delims
class, ,
is a valid path character.
Ruby's URI.extract()
, as suggested in this and this highly-voted answer, is not as smart as Stack Overflow.
2.2.5 :002 > URI.extract('...such as http://example.com/.')
=> ["http://example.com/."]
2.2.5 :003 > URI.extract('Likewise, if I type http://example.org/, Stack Overflow...')
=> ["http://example.org/,"]
Is there a smarter alternative?