New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

regexifi

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexifi

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Regexifi

A collection of tested common REGEX expressions. Because why re-invent the wheel every time for a new project?

Don't add a bunch of ad-hoc REGEX expressions for common things like email addresses, urls, usernames, time formats - Regexifi instead!

It's not that difficult to add a couple of Regex constant at the top of your class, but it's much more difficult to come up with good, tested and consistent Regex expressions for most common validations.

P.S.: Please, add more examples and tests, and, of course, more REGEXP! Open an issue if you want to discuss a certain expression or if you don't think it's warranted.

Installation

Add this line to your application's Gemfile:

gem 'regexifi'

And then execute:

$ bundle

Or install it yourself as:

$ gem install regexifi

Usage

You can require the whole gem with all REGEXP, or just specific ones

require 'regexifi'

# or

require 'regexifi/email'

# Then include it in your class or call directly


class UrlChecker
  include Regexifi
end
UrlChecker::Url::DOMAIN

# Or use it directly in you code. - these are just regular Regular Expressions, pardon the pun.

"my.email@example.com".match? Regexifi::Email::RFC6068 #=> true
"my.email@example.com".match Regexifi::Email::RFC6068  #=> <MatchData "my.email@example.com">
"my.email@example.com" =~ Regexifi::Email::RFC6068 #=>

List of REGEXP in this library

  • Emails
  • Urls/Domains

Emails

Suggestion: If you want to be absolutely true to the spec, most EMAIL RFC are almost impossible to define using Regex alone. Or it becomes clunky and unwieldy. Here are the most common REGEXP , that are commonly used in the "wild".

If you want to dive a bit more and see why using Regex is not always the best solution - check out this blog post

The top two expressions will get you what you want 99% of the time

Regexifi::Email::DEVISE

Use this if you want to allow internationalized domain names, that use non-Latin alphabet.

Regexifi::Email::IDN

These are also used and are closer to the specs, but they do allow some emails that are for most intents and purposes "spam-y", like john.doe@127.0.0.1

Regexifi::Email::WHATWG
Regexifi::Email::RFC5322
Regexifi::Email::RFC6068
Regexifi::Email::RAILS_TUTORIAL

Refer to code and tests for more details.

Urls

Suggestion: In most cases you can use either URI.parse from Ruby's standard library or an excellent Bob Aman's Addressable gem https://github.com/sporkmonger/addressable, to much better effect

Match a domain without http(s) protocol, i.e: https://www.example.com

Regexifi::Url::DOMAIN

Match the whole url with protocol, i.e: https://example.io/article/2/comments?from=registered_users&recent=true

Regexifi::Url::URL

Refer to code and tests for more details.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/regexifi-rb.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Regexifi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

FAQs

Package last updated on 12 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc