D
D
Daria It doesn't matter2021-06-16 16:40:14
Vue.js
Daria It doesn't matter, 2021-06-16 16:40:14

How to remove everything superfluous from a line after the 2nd slash?

Good day
I ran into a problem due to the fact that I don’t know regex well
, for example, there is a string (url)
market/catalog/sea/test/test2/test3
how can I cut everything that comes after sea including a slash so that the output is a string of this type
market /catalog/sea
instead of sea can be any word with any number of letters

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-06-16
@ex123

"market/catalog/sea/test/test2/test3".split('/').slice(0, 2).join('/')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question