Skip to content
Prev 350189 / 398506 Next

regexpr - ignore all special characters and punctuation in a string

Hi Dimitri,

str_replace_all is not in the base libraries, you could use 'gsub' as well,
for example:

a = "What a nice day today! - Story of happiness: Part 2."
b = "What a nice day today: Story of happiness (Part 2)"
sa = gsub("[^A-Za-z0-9]", "", a)
sb = gsub("[^A-Za-z0-9]", "", b)
a==b
# [1] FALSE
sa==sb
# [1] TRUE

Take care of the extra space in a after the '-', so also replace spaces...

Best,
Sven.

On 20 April 2015 at 16:05, Dimitri Liakhovitski <
dimitri.liakhovitski at gmail.com> wrote: