Regex Not Catching All

Hey All!

I have a sticky Regex problem. I am using 3.7 and the Column Expressions node.

My data columns are auto-formatted as Number Double and includes this kind of data

11.2 (good)
15000.25 (good)
123.1234 (bad)
100,000 (bad - but Regex not catching as bad)

I am trying to flag match values to find errors (in everything not matched). I think my logic is wrong or the way the cell handles the ‘,’ might be throwing things off.

The below is matching on what I need. The issue is that its also marking the 100,00 as matched - no issue, when it should be matched as a problem.

?:\d*\.\d{0,2}||\d*)$

Any thoughts/guidance are greatly appreciated!

What are the Blockquote things about?

Also, regex matches Strings; a column of Double data type is just a double number - it doesn’t have thousands separator commas - only when a double value is rendered for the user does it potentially gain a comma - so i’m not sure what you’re trying to do here.

Maybe if you could attach a workflow with some sample data, or state differently what your problem is, a solution would be more clear. ?

1 Like

@quaeler

Thank you for the reply!

I was trying to blockquote the regex code to make it stand out in the post. I will investigate this issue further with the data. I though that I was possibly doing something wrong with my data.

Hi @TardisPilot,

seems to me that what is missing from your first post is criteria/logic when is number good and when is bad. That would clear things a bit :wink:

Is your column type Double or String?

Br,
Ivan

2 Likes

If your column cells are of string type, try this regex:

^\d*.?\d{0,2}$

It matches strings representing numbers with 2 decimal digits maximum, with dot as decimal separator, and without thousands separator.

1 Like

Hey All,

Based on the feedback I just set the cells to String. I guess I didn’t realize that KNIME would auto format them to Double (which added the comma to the number). I really appreciate all of the assistance. The Regex works without issue!

3 Likes

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