In "How do I removing URLs from text?" the following code is suggested:
require 'uri'
#...
schemes_regex = /^(?:#{ URI.scheme_list.keys.join('|') })/i
#...
I tried to improve this to:
schemes_regex = Regexp.union(URI.scheme_list.keys)
but I can't figure out how the IGNORECASE
option (i
) should be specified.
I don't believe it's possible to pass option arguments to Regexp.union
like that. You could of course specify them after the union operation:
require 'uri'
Regexp.new(Regexp.union(URI.scheme_list.keys).source, Regexp::IGNORECASE)
# => /FTP|HTTP|HTTPS|LDAP|LDAPS|MAILTO/i
schemes_regex = Regexp.union(
*URI.scheme_list.keys
.map{|s| Regexp.new(s, Regexp::IGNORECASE)}
)
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