I need to extract the last date only from a string that looks like the following:
Week 1: 03/06/11 – 03/13/11\n
What regex can I use to get ’03/13/11′?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use a regular expression to match both the first and second date and then reference just the second match:
In answer to your other question, the specific regex to match ’03/13/11′ is:
which means:
The advantage of using a regex here is that you can more easily build in flexibility for variable spacing, characters in the string after the second date, etc… For example, this regex works with all of these:
In addition matches[1] is also the first date so you get both dates with the regex too if that’s helpful.
The other methods provided using
splitorindexOfdo not necessarily have the flexibility to automatically work with all these varying formats.