Hi @kamleshp,
I’m not quite sure what you are wanting the regex to match but since you have the ^ symbol inside the square bracket this acts to negate the \d, so the first part will be trying to match two non-digits. If you were wanting to use ^ to represent “start of line” then it needs to be before the square bracket. It isn’t necessary in this case.
The other problem you have is that the \
sign needs to be entered in Column Expression regex as a pair \\
This is because the javascript on which it is based treats the first \
as an escape, so you need to “escape the escape” so that it gets fed correctly as a single \
to the regex parser.
I’ve attached a sample with several different regex patterns as an example
// returns A if format is nn/nn/nnnn , allowing 1 or 2 digits for month and day
if (regexMatcher(column("column1"),"\\d{1,2}/\\d{1,2}/\\d{4}"))
{"A"}
else
// returns B if format is nnnn-nn-nn, allowing 1 or 2 digits for month and day
if (regexMatcher(column("column1"),"\\d{4}-\\d{1,2}-\\d{1,2}"))
{"B"}
else
// returns C if format is nn-nn-nnnn, requiring 2 digits for month and day, else D
if (regexMatcher(column("column1"),"\\d{2}-\\d{2}-\\d{4}"))
{"C"}
else
{"D"}
Note that if this is all you need to do, it is more easily (and probably more efficiently) done with a Rule Engine as follows:
$column1$ MATCHES "\d{1,2}/\d{1,2}/\d{4}"=> "A"
$column1$ MATCHES "\d{4}-\d{1,2}-\d{1,2}"=> "B"
$column1$ MATCHES "\d{2}-\d{2}-\d{4}"=> "C"
TRUE => "D"
Note that with the Rule Engine, you DON’T escape the \
, so that’s something to be wary of.
column expression date regex.knwf (8.4 KB)