Add TRUE/FALSE indicator for column contains at least 1 digit

Hi,

May I know how to add a column “Type” to indicate if column “Amount 1” & “Amount 2” contains at least 1 digit ?
Thinking to use string manipulation but not sure which function should i use
image

Regards,
Ming

Hi @mmngeoh , you can do this using Regular Expressions via nodes such as Rule Engine or Column Expressions.

Hi @bruno29a,

Could you please share the regular expression to use? I am not familiar with Regex

In a Column Expression, you can use

if (regexMatcher(column("column1"),"\\d.*") == true && regexMatcher(column("column2"),"\\d.*") == true) {
    "TRUE"
} else {
    "FALSE"
}

It checks wether column 1 and 2 contains a digit (\d). If your data is null (reflected by a ?), then you need to add additional statement to assure that column 1 and 2 are != null.

image

As alternative, add a Missing Value node and convertt the null to a blank space for example.

Hi @ArjenEX,

Thanks for your help. Based on your Regex, i have done some modification and it reflects what i want:
if (column(“Amount 1”) == null || column(“Amount 1”) == 0)
{
“FALSE”
} else {
if (regexMatcher(column(“Amount 1”),“\d.*”))
{
“TRUE”
} else {
“FALSE”
}
}

Meaning if column “Amount 1” has “0” or is blank, then it will reflect “false” in additional column created as indicator

1 Like

Hi @mmngeoh , to help you with regex, you need to clarify or confirm what you mean by “if column “Amount 1” & “Amount 2” contains at least 1 digit”

If I’m reading this, then A1BCDEF for example should return TRUE, since it contains at least 1 digit, in which case, I belive the expression that @ArjenEX has given will not evaluate this as true.

Can you please confirm if the above sample should evaluate to true or false?

And FYI, the Rule Engine node would run much faster than the Column Expressions (I still don’t understand @ArjenEX 's “obsession” with Column Expressions :smiley: )

1 Like

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