require 'twitter_username_extractor/version'

module TwitterUsernameExtractor
  class Error < StandardError; end

  def self.extract(t)
    return if t.to_s.empty?
    return Regexp.last_match(1) if t.match(/^\@(\w+)$/)
    return Regexp.last_match(1) if t.match(/^(\w+)$/)
    return Regexp.last_match(1) if t.match(%r{(?:www.)?twitter.com/@?(\w+)$}i)

    # Odd special cases
    return Regexp.last_match(1) if t.match(%r{twitter.com/search\?q=%23(\w+)}i)
    return Regexp.last_match(1) if t.match(%r{twitter.com/#!/https://twitter.com/(\w+)}i)
    return Regexp.last_match(1) if t.match(%r{(?:www.)?twitter.com/#!/(\w+)[/\?]?}i)
    return Regexp.last_match(1) if t.match(%r{(?:www.)?twitter.com/@?(\w+)[/\/]?}i)
    fail Error, "Unknown twitter handle: #{t}"
  end
end

require 'twitter_username_extractor/version'

module TwitterUsernameExtractor
  class Error < StandardError; end

  def self.extract(t)
    return if t.to_s.empty?
    return Regexp.last_match(1) if t.match(/^\@(\w+)$/)
    return Regexp.last_match(1) if t.match(/^(\w+)$/)
    return Regexp.last_match(1) if t.match(%r{(?:www.)?twitter.com/@?(\w+)$}i)

    # Odd special cases
    return Regexp.last_match(1) if t.match(%r{twitter.com/search\?q=%23(\w+)}i)
    return Regexp.last_match(1) if t.match(%r{twitter.com/#!/https://twitter.com/(\w+)}i)
    return Regexp.last_match(1) if t.match(%r{(?:www.)?twitter.com/#!/(\w+)[/\?]?}i)
    return Regexp.last_match(1) if t.match(%r{(?:www.)?twitter.com/@?(\w+)[\/]?}i)
    fail Error, "Unknown twitter handle: #{t}"
  end
end

Remove unneeded part of regex
Remove unneeded part of regex

There was an extra `/` in the regex to match one of the known types of
Twitter urls. This was resulting in a warning [1] when the library was
required.

1: 7e4d60bb52e7426496334c70e72cb15c9e8c35ea@?(\w+)[\/\/]?/
