How can I select only alphabets and spaces from a string?
I am currently doing some data cleaning and I would like to remove any characters in a string which are not alphabets or spaces. How can I do this? I'm stuck!
Best Answer
B
Bryan Yap
said
about 7 years ago
Good question! You should be able to do this using the formula .gsub(/[^a-zA-Z\s]/, "") in formula mode.
The way the .gsub function works is that it uses the /[^a-zA-Z\s]/ regular expression to select for characters which are not alphabets or spaces with the empty string, "".
You may find some examples of how it can be used below.
Step 1: Input Data
Step 2: Formula to clean the String
Step 3: The results
Answer
Bryan Yap
said
about 7 years ago
Good question! You should be able to do this using the formula .gsub(/[^a-zA-Z\s]/, "") in formula mode.
The way the .gsub function works is that it uses the /[^a-zA-Z\s]/ regular expression to select for characters which are not alphabets or spaces with the empty string, "".
You may find some examples of how it can be used below.
Saul Macht
How can I select only alphabets and spaces from a string?
I am currently doing some data cleaning and I would like to remove any characters in a string which are not alphabets or spaces. How can I do this? I'm stuck!
Good question! You should be able to do this using the formula .gsub(/[^a-zA-Z\s]/, "") in formula mode.
The way the .gsub function works is that it uses the /[^a-zA-Z\s]/ regular expression to select for characters which are not alphabets or spaces with the empty string, "".
You may find some examples of how it can be used below.
Step 1: Input Data
Step 2: Formula to clean the String
Step 3: The results
Bryan Yap
Good question! You should be able to do this using the formula .gsub(/[^a-zA-Z\s]/, "") in formula mode.
The way the .gsub function works is that it uses the /[^a-zA-Z\s]/ regular expression to select for characters which are not alphabets or spaces with the empty string, "".
You may find some examples of how it can be used below.
Step 1: Input Data
Step 2: Formula to clean the String
Step 3: The results