'Regex date replace
I have dates like the following (note trailing 'T')
2011-11-07T15:24:28
2011-11-07T
With regex i need to extract just the date part so both will look like this
20111107
20111107
.net
Have a webservice that is returning a date like 2011-11-07T15:24:28, but on some occasions it returns date with no time but still with the trailing T. This causes .net's cdate function to bail out.
Solution 1:[1]
Is this so trivial?
/(\d{4})-(\d\d)-(\d\d)/
Use backreferences $1$2$3 as your result.
Or is there something you are not telling us?
Solution 2:[2]
Here is my suggestion. The Regex is:
(\d{4})-(\d{2})-(\d{2})T
The replacement:
$1$2$3
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | FailedDev |
| Solution 2 | Fischermaen |
