R-snippet Regex character and digits (after digits character only)

Hi Knimers!

So, I am dealing with the following issue. Lets say the cell looks like this:

Column Name: Region

Content of cell: Area 34 John, Baker

I want to create two splits. One new column will have: 34, and the other new column will have: John, Baker

I use R-snippet, specifically the script is:

knime.out <- knime.in
library(stringr)
Region_Area<-as.numeric(str_extract(knime.in$"Region", "[0-9]+"))
knime.out$Region_Area<-Region_Area
Responsible<-gsub("[[:digit:]]","",knime.in$"Region")
knime.out$Responsible<-Responsible

So, the column Region Area gets: 34

and the column Responsible gets: Area Jonh, Baker

But I do not want the "Area" with the name of the person. How can I amend my code to get only the character that come after the digits, and not all the characters as it happens in my case.

Hi,

depending on how generic your solution has to be, one way is to change the gsub command to

gsub(".*[[:digit:]] ","",knime.in$"Region")

I just added .* to match everything that comes before the digits and a space after the digits.

Is there a special reason why you do this with an R snippet? The String Manipulation node has among many others a regexReplace function with does exactly the same for you.

Hope that helps.

Cheers,
Marten