I have following dates:
@"August 25-27, 2013"
@"June 5-9, 2013"
@"May 20, 2014"
I need a regex which gives me the out put as follows:
@"August 25 2013"
@"June 5 2013"
@"May 20 2014"
I have following dates:
@"August 25-27, 2013"
@"June 5-9, 2013"
@"May 20, 2014"
I need a regex which gives me the out put as follows:
@"August 25 2013"
@"June 5 2013"
@"May 20 2014"
(\w{3,}) (\d+).*?(\d{4})
$1 $2 $3
Here is also an extremely specific version that will pick up only month names (including 3 letter month names ie. Jan,Feb,Mar,Nov) for the first bit.
(?<month>(?:Jan(:?uary)?)|(?:Feb(:?ruary)?)|(?:Mar(:?ch)?)|(?:Apr(:?il)?)|(?:May)|(?:Jun(:?e)?)|(?:Jul(:?y)?)|(?:Aug(:?ust)?)|(?:Sep(:?tember)?)|(?:Oct(:?ober)?)|(?:Nov(:?ember)?)|(?:Dec(:?ember)?)) (?<day>\d+).*?(?<year>\d{4})
It uses named captures so you would have the changed the replacement text to:
${month} ${day} ${year}
Regex matches are the substring of the original string, you won't be getting desired result in one match, you will be getting two matches and concatenation will yield the desired result. I would suggest to replace the unnecessary stuff with empty string. For that you can use:
((\-\d+)?,)
echo "August 25-27, 2013" | sed -e "s/\\-[0-9]*//" -e "s/,//"
Output: August 25 2013
echo "June 5-9, 2013" | sed -e "s/\\-[0-9]*//" -e "s/,//"
Output: June 5 2013
echo "May 20, 2014" | sed -e "s/\\-[0-9]*//" -e "s/,//"
Output: May 20 2014
Have run on my os x 10.9