
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
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.
Add this line to your application's Gemfile:
gem 'regexifi'
And then execute:
$ bundle
Or install it yourself as:
$ gem install regexifi
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 #=>
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.
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.
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.
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/regexifi-rb.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Regexifi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that regexifi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.