regexes in calendar
I have a string in date format 06/09/2011 03:00 PM
开发者_JS百科. I want to remove all of the forward slashes, and if the first digit of the month (06
) is a zero, remove it as well as the first digit of the day (09
) remove it as well. Any body who can help me out?
thanks!
The usual way to do this is by taking an available date parser where you hand in the input format and output it to a different output format.
Patterns differ, Implementations etc differ also. It is not convenient neither practicable to do date parsing via regex.
Something like that
0([1-9]+)/0([1-9]+)/([0-9]+)
Of course, it will only work in valid dates; it does not parse the date or anything.
BTW: I find better (more readable, detects errors in a more meaningful manner) fyr's answer. This is just to show that it can be done with regex, if fyr's solution is not available in your platform.
精彩评论