RegEx Split Node outputs last pattern match, but I need the first one

Hello everyone, I am having difficulties with the RegEx Split Node.I have several data from which I want to extract dimensions in millimetres. Here is some exemplary data:

Row 1: 0183840 2 mm 4 mm 3487209 28349…
Row 2: 3483482 324 3.2 mm 4begrb…
Row 3: 2354734 SGV 34 EB 10 mm 10.5 mm 11 mm 04r504…

I need the first dimension in each case, i.e. in

Row 1: 2 mm
Row 2: 3.2 mm
Row 3: 10 mm

Unfortunately, the RegEx Split Node always outputs the last hit, but I need the first result from the left. The number of measurements per row varies, sometimes there is one, sometimes two, three or even more. I always need only the first from the left (if necessary as a decimal number). I have used different patterns, e.g. this one:

(\d+,?\d*\smm) with .* around

Thanks in advance

Hi @smallcarp ,
this regex seems to work better
^.+?([\d.]+\smm).$

1 Like

Thank you very much! I have adjusted the pattern a little and now it works perfectly.

I’m sorry, I forgot to escape some chars. This is the correct string
^.+?([\d\.]+\s*mm).*$

Hi
Why did you include the $ at the end?

I should have used preformatted text, silly of me:
^.+?([\d\.]+\s*mm).*$

in this context “^” and “$” respectively mean “start” and “end” of the string to be evaluated.

1 Like

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