1

For example in routes.rb I have something like

  namespace :api do
    namespace :v1 do
      post 'login/:email' => 'authentication#login', email: /[^\/]+/
    end
  end

Given the string "/api/v1/login/lisa@example.com" I would like to know that this path contains a param called email whose value is lisa@example.com

galiat
  • 54
  • 1
  • 4
  • To clarify, this isn't just for email, a more general question. For example, `get 'foo/:id' => 'foo#show'` Given the path `"/foo/123"`, I would like to know this path contains a parameter called `id` whose value is `123` – galiat Apr 04 '18 at 15:34

1 Answers1

0

You could use the following regex

/[\w+\-.]+@[a-z\d\-.]+\.[a-z]+/

This would give you the result

"/api/v1/login/lisa@example.com".scan(/[\w+\-.]+@[a-z\d\-.]+\.[a-z]+/).first

#=> "lisa@example.com"
Yoko
  • 793
  • 10
  • 19