How to keep only digits in a cell in OpenRefine using GREL

137 views Asked by At

For example, the cell contains

5.6
4
5years
6years

How can I make it so it will only keep the digits?

Expected output:

5.6
4
5
6
1

There are 1 answers

0
b2m On

I would use regular expressions for this task.

So for example use the transformation dialog via "Edit cells" => "Transform..." and the GREL Expression:

value.find(/\d+(\.\d+)?/).join(" ")

This will search for decimal like digits in the text and then concatenate (join) the resulting list (array) via whitespace.