Need help - make a simple regular season:

str = 'New/123/папка/123/713' 

It is necessary to cut the string from the end to the / character. The expression must be universal. Grateful for the help.

Closed due to the fact that off-topic participants Wiktor Stribiżew , Dmitry Kozlov , aleksandr barakin , 0xdb , Air 19 Nov '18 at 21:09 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • " Learning tasks are allowed as questions only on the condition that you tried to solve them yourself before asking a question . Please edit the question and indicate what caused you difficulties in solving the problem. For example, give the code you wrote, trying to solve the problem "- Wiktor Stribiżew, Dmitry Kozlov, aleksandr barakin, 0xdb, Air
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    str.substring(0, str.lastIndexOf("/") + 1) - Wiktor Stribiżew

2 answers 2

 var str = 'New/123/папка/123/713'; //разбиваем строку в массив var arr = str.split('/'); //удаляем последний элемент массива arr.pop(); //формируем новую строку var newStr = arr.join('/')+'/'; console.log(newStr); 

  • What you need) Grateful. - Vladislav
  • @greg zakharov is fine) But I wrote with comments so that the author better understood the logic of what is happening and the next time I could use these methods. - Vincent

 var str = "New/123/папка/123/713", rgx = /([aA-zZ0-9-]+$)/; console.log(str.replace(rgx, "")); 

  • @gregzakharov thanks) asked to trim the string. You can also str.slice(0, str.search(/([aA-zZ0-9-]+$)/)) - Evgeny Nikolaev