eparreno / ruby_regex Goto Github PK
View Code? Open in Web Editor NEWRuby regular expressions library
Home Page: www.eparreno.com
License: MIT License
Ruby regular expressions library
Home Page: www.eparreno.com
License: MIT License
Sometimes you want to validate that an attribute matches one (and only one) option out of a given list.
# You allow those options
options = %w(one two)
# You generate this Regex with a GREAT amount of human effort
/\Aone\z|\Atwo\z/.match('three')
This could be generated with a method:
RubyRegex::one_of_these(options)
# or maybe
RubyRegex::Generator::one_of_these(options)
=> /\Aone\z|\Atwo\z/
Would you consider adding regex generators, as such? If so, I could send a PR with this particular case.
Validation is one great usage of regex in ruby but I use searching more often than validation and there must be others that could take advantage of expanding the scope of this project.
Would you be interested in expanding the scope of this project to search for the defined regex in a larger context as well as the current usage of validation of a string only containing the desired pattern?
Since the current regex for each locates each on a line by itself it seems as if having an option to locate them in a line would be helpful. Nesting regex is quite simple in ruby and could be used to keep it dry.
email = /([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w-]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/i
email_validation = /^#{email}&/
"this is my email: [email protected]"[email]
=> "[email protected]"
"[email protected]"[email_validation]
=> "[email protected]"
"this is my email: [email protected]"[email_validation]
=> nil
I can propose more some samples and examples of usage if necessary. Obviously some thought has to be invested in organization and backwards compatibility.
Thanks for your consideration!
I just pulled the GEM from RubyGems and some of my tests failed. I tested also against the Email regex from the source code and that worked. It took me 1 hour until I found this commit: c78eef0. This is not included in the GEM on RubyGems. Would be nice if you would release a new version a publish a new GEM on RubyGems.
Many Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.