Extract first number from string

Hi! I am having trouble trying to work out how to split out the first number from a string. It sometimes has a decimal and sometimes is an integer. I am thinking regex split is the right approach but am getting stuck.

My data (and desired output) looks like this
InputColumn DesiredOutputColumn
3F 2D 3
3 full time 3
3.2F 3.2
6P 6

Any ideas?

Hi,
you can use a Column Expressions node with the following expression: column("yourcolumnname").match(/^[0-9]+(\.[0-9]+)?/)[0]. You might need to install the appropriate extension to use it.
Kind regards
Alexander

3 Likes

Hi @henryhcraig,

In addition to @AlexanderFillbrunn’s solution, I have 2 more options for you:

1- Using the String Manipulation with this expression:
regexReplace($InputColumn$, "(^\\d(?:\\.\\d+)?).*", "$1")

2- Using Regex Extractor from Palladian nodes version 2 with this regex:
^\d+(?:\.\d+)?

:blush:

5 Likes

Thanks - it worked! Appreciate your help.

2 Likes

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