1

I have a string like this

string = '/location/start:2015-06-06/end:2015-06-06'

and I would substitute the start and end paramaters. Therefore, I would like to delete everything like start:2015-06-06 and end:2015-06-06 by using Regexp.

But I do not know how.

2

2 Answers 2

2
string = string.replace(/start:[\d-]*/g,"").replace(/end:[\d-]*/g,"");
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, brain is running slow today. That should be: string.replace(/(start|end):[\d-]*/g,'');
0

This should work:

var str = '/location/start:2015-06-06/end:2015-06-06'; 
var result = str.replace(/start:[0-9]{4}-[0-9]{2}-[0-9]{2}/, 'something');

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.