1

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.

2
  • 1
    show us your attempt Commented Jul 18, 2016 at 13:39
  • @Rory - I tried test.replace(/\d+/g, ''); It removes all numbers Commented Jul 18, 2016 at 13:41

3 Answers 3

2

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 );

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much
@MohammedFarooq glad to know it helped :)
0

An alternative solution is to search for a digit (\d+) followed by a * (\*) and replace it with nothing.

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

var edited=dynamic.replace(/\d+\*/g, '');

console.log(edited);

Comments

0

Here is another way using split and join:

var str = '/1*Region 1/42*Europe/51*Test/100*New Folder/119*New Folder',
    result = str.split(/\d+\*/).join('');   

console.log(result);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.