[2022-01-04T11:41:50.866Z] ### Step X
[2022-01-04T11:49:37.836Z] ### Step Y
[Error] Not Found ....
[couchbaseUtils] Not Found...
[2022-01-04T19:00:59.833Z] [INFO] [2022]
I want to remove all the dates [2022-01-04T11:41:50.866Z] using Regex.
What would be the right pattern for this? I would like to learn. Thanks!
>Solution :
I don’t know what language you are using. But here is a very simple regex that should work on almost all languages.
\[\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z\]
It’s a very simple regex that exactly matches your date and time format. If you still need explanation, I think the one provided on the top-right in the link I posted should be sufficient.
If you are using java, you can do it the following way.
input = input.replaceAll("\\[\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z\\]", "");
It finds the string in the given regex pattern and replaces it.