0

for example 21/10/2013.. I want to remove the /2013..

replace('/2013', '') work but the date might be other value like 2014, 2015 and so on

5
  • 3
    If it's always in this format, could you split, pop, then join? Commented Oct 21, 2013 at 4:33
  • "21/10/2013".replace(/\/\d{4}$/g,''); Commented Oct 21, 2013 at 4:43
  • @CoreyRothwell: comments are not for answering the question if you know it works - if it does answer the question (which it does), please post it as an answer. Thansk! Commented Oct 21, 2013 at 4:53
  • Why not just .substring(0, 5), assuming the day and month values are zero-padded. Commented Oct 21, 2013 at 5:56
  • Or .slice(-5), assuming this is not meant to be used in the year 10k+. Commented Oct 21, 2013 at 6:23

2 Answers 2

2

This removes everything from the last / onwards:

var str = "21/10/2013";
var new_str = str.substring(0,str.lastIndexOf('/'));
Sign up to request clarification or add additional context in comments.

Comments

2

Try:

'21/10/2013'.replace(/\/\d+$/,''); // 21/10

which removes the last "/" and any digits following to the end of the string.

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.