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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40966cc63071e62d563e7a5de1a924c8daa34aae
4
- data.tar.gz: d664c37af40dcd7d9089cf115c67c6f91df1ec66
3
+ metadata.gz: 598e3dce59c516054e30d9b079a7dd93ee8c8ee9
4
+ data.tar.gz: 5d861d4f7b6cc4d0d36d6629cf254bce7e9b3696
5
5
  SHA512:
6
- metadata.gz: d405294eeba9f227606523f9829085fd40eb99ba581e80a63610d380cc7f58509cbca8d234d4f924a83fad781947511bae8f6b2f712d9d5e309931c03c9ee466
7
- data.tar.gz: f3a33ef9791a26ae03c509fbf910148a4ebe597789f746c48d1de45c470ace6fbe5bafb744bcd06dd8108093b34c9d17c229f57eb6449867d5fe448807cd24ef
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 `$` from first regex and leading `^` from second regex.
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$/i) | /bar/ # => /foobar/i
64
- Regexy::Regexp.new(/foo/).or '^bar' # => /foobar/
65
- Regexy::Regexp.new(/^foo$/).or '^bar$' # => /^foobar$/
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
- new_regexp = source.chomp('$') + other.source.sub(/^\^/, '')
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
@@ -1,3 +1,3 @@
1
1
  module Regexy
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -0,0 +1,13 @@
1
+ # encoding: UTF-8
2
+
3
+ module Regexy
4
+ module Web
5
+ class Hashtag < ::Regexy::Regexp
6
+ HASHTAG = /\A#(?=.{2,140}\z)([0-9_\p{L}]*[_\p{L}][0-9_\p{L}]*)\z/u.freeze
7
+
8
+ def initialize(*args)
9
+ super(HASHTAG, *args)
10
+ end
11
+ end
12
+ end
13
+ end
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])$/i.freeze
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 = /^(?:(?: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]?)$/i.freeze
7
- IPV4_WITH_PORT = ::Regexp.new(IPV4_NORMAL.source.chomp('$') + PORT.source).freeze
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 = /^(?:(?:(?:[A-F0-9]{1,4}:){6}|(?=(?:[A-F0-9]{0,4}:){0,6}(?:[0-9]{1,3}\.){3}
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('[' + IPV6_NORMAL.source.chomp('$') + ']' + PORT.source).freeze
30
+ IPV6_WITH_PORT = (::Regexy::Regexp.new(/\A\[/) + IPV6_NORMAL + /\]/ + PORT.source).freeze
31
31
 
32
32
  protected
33
33
 
@@ -3,13 +3,13 @@
3
3
  module Regexy
4
4
  module Web
5
5
  class Url < ::Regexy::Regexp
6
- URL = /^([a-z][a-z\d+\-.]*:(\/\/([\p{L}\d\-._~%!$&'()*+,;=]+@)?([\p{L}\d\-._~%]+|
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, 'regexy/web/email'
4
- autoload :IPv4, 'regexy/web/ip'
5
- autoload :IPv6, 'regexy/web/ip'
6
- autoload :Url, 'regexy/web/url'
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.2
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-13 00:00:00.000000000 Z
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