REGULAR EXPRESION FOR DATE AND HOUR

I am not good with regular expresions and I want to use String Manipulation with RegexMatcher but I do not know how to write correctly the regular expresion.

I NEED TO GET THE EXPRESION OF THIS
image

AND I TRIED WITH THIS
image

Hi @alexis1701

A proper Regex really depends on the amount of different formats it needs to capture. If it just hh:mm:ss and dd/MM/yyyy like in your sample, then the RegexMatcher (\\d{2})/(\\d{2})/(\\d{4})|(\\d{2}):(\\d{2}):(\\d{2})(.*) should work.

It consists of two groups separated by the pipe representing an OR statement:

  1. date group: two digits (dd) + / + two digits (MM) + / + four digits (yyyy)
  2. time group: two digits (hh) + : + two digits (mm) + : + two digits (ss) + wildcard to capture a.m.&p.m.

Depending on the expected inputs, your Regex might have to be tweaked a little bit. As such, if you need to capture more formats, you can add them with a | separator. You can easily play around with it here: RegExr: Learn, Build, & Test RegEx (mind the escape characters that you have to use in KNIME)

An example of this Regex in action in KNIME:

I took some of your input values and added a few more to show how the Regex behaves with other inputs.

WF: REGULAR EXPRESION FOR DATE AND HOUR.knwf (12.2 KB)

Hope this provides some inspiration.

3 Likes

What’s your goal. If you only like to extract the dates you need to add your forward slashes “/” in your regex as well and not “commas”
br

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.