Forum Discussion
Anonymous
7 years agoNot applicable
Filtering a text column for a specific pattern
Hi all, I have a text column containing part numbers. There are many different patterns for the part number, some containing just numbers, some having numbers separated by a hyphen, different len...
- 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
Anonymous
3 years agoNot applicable
I have managed to do it with the below! 🙂