V
V
vadimstroganov2015-11-08 14:12:31
Ruby on Rails
vadimstroganov, 2015-11-08 14:12:31

How to cut part of URL up to a certain point?

Hello!
There is a url:

http://localhost:3000/Users/user_name/projects/domain/post/image/63/dfe8b2f18890813bdfc53ed2c0982d73.png

How to remove everything up to post/image/63/dfe8b2f18890813bdfc53ed2c0982d73.png through regexp?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2015-11-08
@vadimstroganov

Regulators are not needed.
Based on the resources indicated in the config/routes routes, you can find out which resource generates localhost:3000/Users/user_name/projects/domain
Then, you check if the search string is in the full path using index. If from position 0, then with a regular slice of a string array you extract a part, starting from the index of the length of the string you are looking for.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question