-1

I have timestamps in a field and would like to remove the 'T' and the 'Z' in the value. An example value is 2019-11-01T14:47:43Z. I would like to use a RegEx to solve this problem. I plan to use this in Java.

Geoffrey West
  • 241
  • 1
  • 8
  • 17
  • Do you just want to remove "T" and "Z" or do you want to remove all letters from the timestamp? Are you going to slice them out or replace them with spaces? What programming language do you plan to use to do this? Perl and Python are two popular picks, but until we have more detail, this question can't be answered. – Nick Reed Dec 09 '19 at 17:51
  • Updated, I will use Java. – Geoffrey West Dec 09 '19 at 17:52
  • @GeoffreyWest Have you tried parsing the timestamp? [This answer](https://stackoverflow.com/a/6543193/10552687) may help you – dvo Dec 09 '19 at 17:56
  • Don’t use regular expressions if you don’t have to. `s.substring(0, 10) + s.substring(11, 19)` is sufficient. – VGR Dec 09 '19 at 19:38

1 Answers1

0

You can use Java's String.replaceAll() function to remove values with regex. The regular expression [a-zA-Z] will match any one letter; replacing it with an empty string will remove it entirely.

    String ts = "2019-11-01T14:47:43Z";
    System.out.println(ts.replaceAll("[a-zA-Z]", ""));

2019-11-0114:47:43

Demo

Nick Reed
  • 5,029
  • 4
  • 14
  • 34