Forum Discussion
Filtering a text column for a specific pattern
- 7 years ago
Best bet is to create custom function. But it requires iterating through string, not particulary smart or easy to do.
I'd suggest using R Script in the query editor.
pattern <- "^[[:alpha:]]{3}\\-\\d{4}" isMatch <- function(x) {grepl(pattern, as.character(x), ignore.case=TRUE)} return <- within(dataset,{Flag=isMatch(dataset$PartNumber)})Replace "PartNumber" with your actual column name.
return.
Then it's simply filtering based on "Flag" column.
Edit: You can find RegEx pattern cheat sheet for R in link below.
https://www.rstudio.com/wp-content/uploads/2016/09/RegExCheatsheet.pdf
Best bet is to create custom function. But it requires iterating through string, not particulary smart or easy to do.
I'd suggest using R Script in the query editor.
pattern <- "^[[:alpha:]]{3}\\-\\d{4}"
isMatch <- function(x) {grepl(pattern, as.character(x), ignore.case=TRUE)}
return <- within(dataset,{Flag=isMatch(dataset$PartNumber)})Replace "PartNumber" with your actual column name.
return.
Then it's simply filtering based on "Flag" column.
Edit: You can find RegEx pattern cheat sheet for R in link below.
https://www.rstudio.com/wp-content/uploads/2016/09/RegExCheatsheet.pdf
Hi, thanks for you solution. what if I'd like to apply it to multiple columns? thanks in advance