Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Expanding Usage of RubyRegex from just Validation #3

Open
klappy opened this Issue · 3 comments

2 participants

@klappy

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: user@domain.tld"[email]
=> "user@domain.tld"

"user@domain.tld"[email_validation]
=> "user@domain.tld"

"this is my email: user@domain.tld"[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!

@eparreno
Owner

it sounds interesting. I think it would be a good solution to use namespaces to organize this new feature, for example

RubyRegex::Email (email validation)
RubyRegex::Text::Email (email matching within a text)

What do you think?

@klappy

That seems like a logical solution. What if we took this one step further and name them RubyRegex::Validate::Email and RubyRegex::Search::Email so that the namespace defines its usage and what it does. That way if we expand the project further we could possibly even have RubyRegex::Split::Email (not that one would split a string at every Email but you get the idea that there are other uses for regex). Then RubyRegex < RubyRegex::Validation so that the default remains backwards compatible. This would allow the user to override the default namespace.

Either way I would happy with it and would also be eager to assist.

Thanks again!

@klappy klappy closed this
@klappy klappy reopened this
@klappy

Must have clicked "Comment & Close" instead of "Comment"

@eparreno eparreno self-assigned this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.