diff --git a/README.md b/README.md index 0b0b858..54afd7c 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Regexy is the ruby gem that contains a lot of common-use regular expressions (su * [IP addresses](#regexywebipv4) * [Url](#regexyweburl) * [Hostname](#regexywebhostname) + * [Smiles](#regexytextsmile) - [Contributing](#contributing) ## Installation @@ -137,6 +138,15 @@ Generates regular expressions for matching hostname (with unicode support). ```ruby r1 = Regexy::Web::HostName.new # matches 'foo.com', 'www.foo.com' and 'киррилический.домен.рф' ``` +### Regexy::Text::Smile + +Generates regular expressions for matching smiles. +```ruby +r = Regexy::Text::Smile.new # matches ':)', ':=)', 'xD' and so on +# Find all smiles in text +str = "Check out http://foo.com :). It's awesome :D" +str.scan(r.unbound.internal_regexp).map(&:first) # => [":)", ":D"] +``` ## Contributing Have an idea of new regular expression? Create an [issue](https://github.com/vladimir-tikhonov/regexy/issues) (some test cases will be much appreciated) or open a [pull request](https://github.com/vladimir-tikhonov/regexy/pulls). diff --git a/lib/regexy.rb b/lib/regexy.rb index c765ad1..8008d6e 100644 --- a/lib/regexy.rb +++ b/lib/regexy.rb @@ -1,7 +1,8 @@ require 'regexy/version' module Regexy - autoload :Regexp, 'regexy/regexp' + autoload :Regexp, 'regexy/regexp' autoload :RegexpWithMode, 'regexy/regexp' - autoload :Web, 'regexy/web' + autoload :Web, 'regexy/web' + autoload :Text, 'regexy/text' end diff --git a/lib/regexy/text.rb b/lib/regexy/text.rb new file mode 100644 index 0000000..1cbb170 --- /dev/null +++ b/lib/regexy/text.rb @@ -0,0 +1,5 @@ +module Regexy + module Text + autoload :Smile, 'regexy/text/smile' + end +end \ No newline at end of file diff --git a/lib/regexy/text/smile.rb b/lib/regexy/text/smile.rb new file mode 100644 index 0000000..16c7236 --- /dev/null +++ b/lib/regexy/text/smile.rb @@ -0,0 +1,11 @@ +module Regexy + module Text + class Smile < Regexy::Regexp + SMILE_REGEX = /\A((?