easy-regex 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +38 -0
- data/lib/easy-regex.rb +60 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9c77f486f2238fcd65eeb5a77411401273e56f86e34b05ff14650fef38eb063e
|
4
|
+
data.tar.gz: 4e46f98e8343119a573fcf509a59f0720fa421ffaa9da7ffb02cb2227067e0f7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eef9b6c873d64a8b8a175670e74c3e6ec451a0deaf468dce98c5da1f2206272a0f47006527905c5ec2ba5a27062b8ecfb3b36fef711592c78c566abd4de613ae
|
7
|
+
data.tar.gz: 725b61ef74126f264a7d20e3847ce4ef1d4f94fca88a25273a0c231f13216ce1172a3c2c336de942b98fe0cf8136e866f3b1b01bdb88de0ed48e0718f44f3a3e
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# easy-regex-gem
|
2
|
+
|
3
|
+
easy-regex gem allows you to use and create regular expressions in a very easy way. You can also create custom regular expressions.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
- Make it easy to obtain regular expressions.
|
8
|
+
- Allow to create custom regular expressions.
|
9
|
+
- To create custom regular expressions, certain parameters must be passed.
|
10
|
+
- The gem should have the following common regular expressions:
|
11
|
+
- Url.
|
12
|
+
- Domain.
|
13
|
+
- Email.
|
14
|
+
- Password.
|
15
|
+
- Name.
|
16
|
+
- Phone number.
|
17
|
+
- Address
|
18
|
+
- Regular expressions must be classified according to their function.
|
19
|
+
|
20
|
+
## Use
|
21
|
+
|
22
|
+
- Install the gem *easy-regex* `gem install easy-regex-x.x.x.gem`
|
23
|
+
- Use the gem `require 'easy-regex'`
|
24
|
+
- Call the module `ERegex` follow by the class `(Internet|Personal)` and the regex `ERegex::Internet.email`
|
25
|
+
- Classification
|
26
|
+
- Internet
|
27
|
+
- email
|
28
|
+
- email_custom(domain->String, length->Integer)
|
29
|
+
- password
|
30
|
+
- password_custom(length->Integer, start_with->String, end_with->String)
|
31
|
+
- domain
|
32
|
+
- domain_custom(length->Integer, end_with->String)
|
33
|
+
- url
|
34
|
+
- Personal
|
35
|
+
- name
|
36
|
+
- phone
|
37
|
+
- phone_custom(phone_region->Boolean, spaces->Boolean)
|
38
|
+
- address
|
data/lib/easy-regex.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module ERegex
|
2
|
+
class Internet
|
3
|
+
class << self
|
4
|
+
def email
|
5
|
+
# Regex to validate an email -> from Michael Hartl Rails book
|
6
|
+
/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
|
7
|
+
end
|
8
|
+
|
9
|
+
def email_custom(domain, length)
|
10
|
+
/\A[\w+\-.]{1,#{length}}@#{domain}\z/i
|
11
|
+
end
|
12
|
+
|
13
|
+
def password
|
14
|
+
# Regex if a string contains at least a lowercase letter, a uppercase, a digit, a scpecial char and +8 chars
|
15
|
+
/^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\W]).{8,}$/
|
16
|
+
end
|
17
|
+
|
18
|
+
def password_custom(length, start_with="", end_with="")
|
19
|
+
/^#{start_with}(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\W]).{#{length},}#{end_with}$/
|
20
|
+
end
|
21
|
+
|
22
|
+
def domain
|
23
|
+
/[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
|
24
|
+
end
|
25
|
+
|
26
|
+
def domain_custom(length, end_with="")
|
27
|
+
return /^[a-z\d\-]{0,#{length}}(\.[a-z\d\-]{0,#{length}})*\.[a-z]+\z/ if end_with.length == 0
|
28
|
+
/[a-z\d\-]{0,#{length}}(\.[a-z\d\-]{0,#{length}})*\.#{end_with}\z/
|
29
|
+
end
|
30
|
+
|
31
|
+
def url
|
32
|
+
/^((http|https):\/\/)(([a-z0-9-\.]*)\.)?([a-z0-9-]+)\.([a-z]{2,5})(:[0-9]{1,5})?(\/)?$/ix
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Personal
|
38
|
+
class << self
|
39
|
+
def name
|
40
|
+
/^\s*[A-Za-z]+((\s)?((\'|\-|\.)?([A-Za-z])*))*\s*$/
|
41
|
+
end
|
42
|
+
|
43
|
+
def phone
|
44
|
+
/\A(\+(\d{1,2}-)?\d{1,4}\s?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}\z/
|
45
|
+
end
|
46
|
+
|
47
|
+
def phone_custom(region, spaces=true)
|
48
|
+
region_regex = /(\+(\d{1,2}-)?\d{1,4}\s?)/
|
49
|
+
region_regex = "" if !region
|
50
|
+
return /\A#{region_regex}\(?\d{3}\)?\d{3}\d{4}\z/ if !spaces
|
51
|
+
|
52
|
+
/\A#{region_regex}\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}\z/
|
53
|
+
end
|
54
|
+
|
55
|
+
def address
|
56
|
+
/\A[\w+\-.]\s(#?\d+)\s[\w+\-.]/
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easy-regex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gregorio Vazquez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Gem to obtain and manipulate the most common regex in a easy way
|
14
|
+
email: gregoriovazya@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- lib/easy-regex.rb
|
21
|
+
homepage: https://github.com/jvargas98
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.2.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Easy regex gem
|
44
|
+
test_files: []
|