regexy 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +14 -4
- data/lib/regexy/regexp.rb +3 -1
- data/lib/regexy/version.rb +1 -1
- data/lib/regexy/web/hashtag.rb +13 -0
- data/lib/regexy/web/ip.rb +6 -6
- data/lib/regexy/web/url.rb +2 -2
- data/lib/regexy/web.rb +5 -4
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 598e3dce59c516054e30d9b079a7dd93ee8c8ee9
|
|
4
|
+
data.tar.gz: 5d861d4f7b6cc4d0d36d6629cf254bce7e9b3696
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 977c292fcbe5a7a74966006c6580ecc48d4562c89d52e1994be3dd0d227fc18b5b3ab93d813c402c8b1a2f351214971f2314d285731249350e28e86170c6a50a
|
|
7
|
+
data.tar.gz: fe3faba108f11c13221a7a9819fa89923ddcdfdf53019ed7c417dc7d809604d0e631749f7b801b86c063e2e571ca728080c28b9b47645d20eba4ccc0b9f87634
|
data/README.md
CHANGED
|
@@ -14,6 +14,7 @@ Regexy is the ruby gem that contains a lot of common-use regular expressions (su
|
|
|
14
14
|
* [General usage](#regexyregexp)
|
|
15
15
|
* [Combining expressions](#combining-regular-expressions)
|
|
16
16
|
* [Email addresses](#regexywebemail)
|
|
17
|
+
* [Hashtag](#regexywebhashtag)
|
|
17
18
|
* [IP addresses](#regexywebipv4)
|
|
18
19
|
* [Url](#regexyweburl)
|
|
19
20
|
- [Contributing](#contributing)
|
|
@@ -57,12 +58,12 @@ Regexy::Regexp.new(/foo/i) | /bar/x # => /foo|bar/ix
|
|
|
57
58
|
Regexy::Regexp.new(/foo/i).or 'bar' # => /foo|bar/i
|
|
58
59
|
any_ipv4 = Regexy::Web::IPv4.new(:normal) | Regexy::Web::IPv4.new(:with_port) # matches ip w\ and w\o port
|
|
59
60
|
```
|
|
60
|
-
Also you could simply join two expressions using `+` method, or it's alias `and_then`. Note, that it will __remove__ trailing
|
|
61
|
+
Also you could simply join two expressions using `+` method, or it's alias `and_then`. Note, that it will __remove__ trailing `\z` from first regex and leading `\A` from second regex.
|
|
61
62
|
```ruby
|
|
62
63
|
Regexy::Regexp.new('foo') + Regexy::Regexp.new(/bar/) # => /foobar/
|
|
63
|
-
Regexy::Regexp.new(/foo
|
|
64
|
-
Regexy::Regexp.new(/foo/).or '
|
|
65
|
-
Regexy::Regexp.new(
|
|
64
|
+
Regexy::Regexp.new(/foo\z/i) | /bar/ # => /foobar/i
|
|
65
|
+
Regexy::Regexp.new(/foo/).or '\Abar' # => /foobar/
|
|
66
|
+
Regexy::Regexp.new(/\Afoo\z/).or '\Abar\z' # => /\Afoobar\z/
|
|
66
67
|
```
|
|
67
68
|
|
|
68
69
|
### Regexy::Web::Email
|
|
@@ -74,6 +75,15 @@ r1 = Regexy::Web::Email.new(:relaxed)
|
|
|
74
75
|
r2 = Regexy::Web::Email.new(:normal) # does not match 'f@s.c' and 'invalid-ip@127.0.0.1.26'
|
|
75
76
|
r2 = Regexy::Web::Email.new(:strict) # does not match 'hans,peter@example.com' and "partially.\"quoted\"@sld.com"
|
|
76
77
|
```
|
|
78
|
+
### Regexy::Web::Hashtag
|
|
79
|
+
|
|
80
|
+
Generates regular expressions for matching Hashtags.
|
|
81
|
+
A hashtag can contain any UTF-8 alphanumeric character, plus the underscore symbol.
|
|
82
|
+
A hashtag can't be only numeric, it must have at least one alpahanumeric character or the underscore symbol.
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
r1 = Regexy::Web::Hashtag.new # matches '#hash_tags'
|
|
86
|
+
```
|
|
77
87
|
### Regexy::Web::IPv4
|
|
78
88
|
|
|
79
89
|
Generates regular expressions for matching IPv4 addresses. Available options: `:normal` (by default) for matching ip without port and `:with_port` for guess what.
|
data/lib/regexy/regexp.rb
CHANGED
|
@@ -23,7 +23,9 @@ module Regexy
|
|
|
23
23
|
|
|
24
24
|
def + other
|
|
25
25
|
other = ::Regexy::Regexp.new(other)
|
|
26
|
-
|
|
26
|
+
first_regex = source.length > 2 ? source.sub(/\\z\s*\z/, '') : source
|
|
27
|
+
second_regex = other.source.length > 2 ? other.source.sub(/\A\\A/, '') : other.source
|
|
28
|
+
new_regexp = first_regex + second_regex
|
|
27
29
|
new_options = options | other.options
|
|
28
30
|
::Regexy::Regexp.new(new_regexp, new_options)
|
|
29
31
|
end
|
data/lib/regexy/version.rb
CHANGED
data/lib/regexy/web/ip.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
module Regexy
|
|
2
2
|
module Web
|
|
3
|
-
PORT = /:([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])
|
|
3
|
+
PORT = /:([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])\z/i.freeze
|
|
4
4
|
|
|
5
5
|
class IPv4 < ::Regexy::RegexpWithMode
|
|
6
|
-
IPV4_NORMAL =
|
|
7
|
-
IPV4_WITH_PORT = ::Regexp.new(IPV4_NORMAL
|
|
6
|
+
IPV4_NORMAL = /\A(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\z/i.freeze
|
|
7
|
+
IPV4_WITH_PORT = (::Regexy::Regexp.new(IPV4_NORMAL) + PORT.source).freeze
|
|
8
8
|
|
|
9
9
|
protected
|
|
10
10
|
|
|
@@ -18,16 +18,16 @@ module Regexy
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
class IPv6 < ::Regexy::RegexpWithMode
|
|
21
|
-
IPV6_NORMAL =
|
|
21
|
+
IPV6_NORMAL = /\A(?:(?:(?:[A-F0-9]{1,4}:){6}|(?=(?:[A-F0-9]{0,4}:){0,6}(?:[0-9]{1,3}\.){3}
|
|
22
22
|
[0-9]{1,3}(?![:.\w]))(([0-9A-F]{1,4}:){0,5}|:)((:[0-9A-F]{1,4}){1,5}:|:)
|
|
23
23
|
|::(?:[A-F0-9]{1,4}:){5})(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|
|
|
24
24
|
[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|
|
|
25
25
|
(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}|(?=(?:[A-F0-9]{0,4}:){0,7}
|
|
26
26
|
[A-F0-9]{0,4}(?![:.\w]))(([0-9A-F]{1,4}:){1,7}|:)((:[0-9A-F]{1,4}){1,7}
|
|
27
|
-
|:)|(?:[A-F0-9]{1,4}:){7}:|:(:[A-F0-9]{1,4}){7})(?![:.\w])
|
|
27
|
+
|:)|(?:[A-F0-9]{1,4}:){7}:|:(:[A-F0-9]{1,4}){7})(?![:.\w])\z
|
|
28
28
|
/ix.freeze
|
|
29
29
|
|
|
30
|
-
IPV6_WITH_PORT = ::Regexp.new(
|
|
30
|
+
IPV6_WITH_PORT = (::Regexy::Regexp.new(/\A\[/) + IPV6_NORMAL + /\]/ + PORT.source).freeze
|
|
31
31
|
|
|
32
32
|
protected
|
|
33
33
|
|
data/lib/regexy/web/url.rb
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
module Regexy
|
|
4
4
|
module Web
|
|
5
5
|
class Url < ::Regexy::Regexp
|
|
6
|
-
URL =
|
|
6
|
+
URL = /\A([a-z][a-z\d+\-.]*:(\/\/([\p{L}\d\-._~%!$&'()*+,;=]+@)?([\p{L}\d\-._~%]+|
|
|
7
7
|
\[[\p{L}\d:.]+\]|\[v[a-f0-9][\p{L}\d\-._~%!$&'()*+,;=:]+\])(:[0-9]+)?
|
|
8
8
|
(\/[\p{L}\d\-._~%!$&'()*+,;=:@]+)*\/?|(\/?[\p{L}\d\-._~%!$&'()*+,;=:@]+
|
|
9
9
|
(\/[\p{L}\d\-._~%!$&'()*+,;=:@]+)*\/?)?)|([\p{L}\d\-._~%!$&'()*+,;=@]+
|
|
10
10
|
(\/[\p{L}\d\-._~%!$&'()*+,;=:@]+)*\/?|(\/[\p{L}\d\-._~%!$&'()*+,;=:@]+)
|
|
11
11
|
+\/?))
|
|
12
|
-
(\?[\p{L}\d\-._~%!$&'()*+,;=:@\/?]*)?(\#[\p{L}\d\-._~%!$&'()*+,;=:@\/?]*)
|
|
12
|
+
(\?[\p{L}\d\-._~%!$&'()*+,;=:@\/?]*)?(\#[\p{L}\d\-._~%!$&'()*+,;=:@\/?]*)?\z
|
|
13
13
|
/ix.freeze
|
|
14
14
|
|
|
15
15
|
def initialize(*args)
|
data/lib/regexy/web.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
module Regexy
|
|
2
2
|
module Web
|
|
3
|
-
autoload :Email,
|
|
4
|
-
autoload :
|
|
5
|
-
autoload :
|
|
6
|
-
autoload :
|
|
3
|
+
autoload :Email, 'regexy/web/email'
|
|
4
|
+
autoload :Hashtag, 'regexy/web/hashtag'
|
|
5
|
+
autoload :IPv4, 'regexy/web/ip'
|
|
6
|
+
autoload :IPv6, 'regexy/web/ip'
|
|
7
|
+
autoload :Url, 'regexy/web/url'
|
|
7
8
|
end
|
|
8
9
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: regexy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vladimir Tikhonov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-03-
|
|
11
|
+
date: 2015-03-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -87,6 +87,7 @@ files:
|
|
|
87
87
|
- lib/regexy/version.rb
|
|
88
88
|
- lib/regexy/web.rb
|
|
89
89
|
- lib/regexy/web/email.rb
|
|
90
|
+
- lib/regexy/web/hashtag.rb
|
|
90
91
|
- lib/regexy/web/ip.rb
|
|
91
92
|
- lib/regexy/web/url.rb
|
|
92
93
|
- regexy.gemspec
|