Reputation: 625
Does Ruby have a gem that provides a canned set of regular expressions (ala Perl's Regexp::Common module)? If not, how does the community share commonly-needed regexps? Thanks.
Upvotes: 1
Views: 46
Reputation: 4517
Yes, kind of.
There is a gem called ruby_regex that does this exact thing. From their github page:
Add to your Gemfile
gem 'ruby_regex'
In the models
validates_format_of :email, :with => RubyRegex::Email
And they have listed regex for:
RubyRegex::Url
RubyRegex::Domain
RubyRegex::Email
RubyRegex::Username
RubyRegex::USSocialSecurity
RubyRegex::GeneralPostalCode
RubyRegex::ZIPCode
RubyRegex::CreditCard
RubyRegex::MasterCard
RubyRegex::Visa
RubyRegex::TwitterUsername
RubyRegex::DeliciousUsername
RubyRegex::SlidesahreUsername
RubyRegex::GithubUsername
RubyRegex::UUID
RubyRegex::DBDate
RubyRegex::DBDatetime
RubyRegex::SpanishBankAccountNumber
RubyRegex::Dni
I'm not sure if they support anything else. There are lots of little one-off projects for this. But I haven't been able to find anything nearly as complete as the perl module.
I also found another one called Cregexp that has limited numbers of them as well.
Upvotes: 1