Mohammed Farooq Mohammed Farooq - 4 months ago 11
Javascript Question

javascript regex to remove particular format text from string

I have a dynamic string and I want to remove particular format text from String. (i.e *Number)

For example:

/1*Region 1/42*Europe/51*Test/100*New Folder/119*New Folder


Output :
/Region 1/Europe/Test/New Folder/New Folder


Thanks in advance.

Answer

var str = "/1*Region 1/42*Europe/51*Test/100*New Folder/119*New Folder";

var regex = /(\/\d+\*)/g;

var output = str.replace( regex, '/' );

console.log( output );