Re: [R] regexpr - ignore all special characters and punctuation in a string

2015-04-20 Thread Dimitri Liakhovitski
Thanks a lot, everybody for excellent suggestions! On Mon, Apr 20, 2015 at 10:15 AM, Charles Determan wrote: > You can use the [:alnum:] regex class with gsub. > > str1 <- "What a nice day today! - Story of happiness: Part 2." > str2 <- "What a nice day today: Story of happiness (Part 2)" > > gsu

Re: [R] regexpr - ignore all special characters and punctuation in a string

2015-04-20 Thread Charles Determan
You can use the [:alnum:] regex class with gsub. str1 <- "What a nice day today! - Story of happiness: Part 2." str2 <- "What a nice day today: Story of happiness (Part 2)" gsub("[^[:alnum:]]", "", str1) == gsub("[^[:alnum:]]", "", str2) [1] TRUE The same can be done with the stringr package if

Re: [R] regexpr - ignore all special characters and punctuation in a string

2015-04-20 Thread John McKown
On Mon, Apr 20, 2015 at 8:59 AM, Dimitri Liakhovitski < dimitri.liakhovit...@gmail.com> wrote: > Hello! > > Please point me in the right direction. > I need to match 2 strings, but focusing ONLY on characters, ignoring > all special characters and punctuation signs, including (), "", etc.. > > For

Re: [R] regexpr - ignore all special characters and punctuation in a string

2015-04-20 Thread Duncan Murdoch
On 20/04/2015 9:59 AM, Dimitri Liakhovitski wrote: > Hello! > > Please point me in the right direction. > I need to match 2 strings, but focusing ONLY on characters, ignoring > all special characters and punctuation signs, including (), "", etc.. > > For example: > I want the following to return:

Re: [R] regexpr - ignore all special characters and punctuation in a string

2015-04-20 Thread Sven E. Templer
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] FAL

Re: [R] regexpr - ignore all special characters and punctuation in a string

2015-04-20 Thread Marc Schwartz
> On Apr 20, 2015, at 8:59 AM, Dimitri Liakhovitski > wrote: > > Hello! > > Please point me in the right direction. > I need to match 2 strings, but focusing ONLY on characters, ignoring > all special characters and punctuation signs, including (), "", etc.. > > For example: > I want the foll

Re: [R] regexpr - ignore all special characters and punctuation in a string

2015-04-20 Thread Dimitri Liakhovitski
I think I found a partial answer: str_replace_all(x, "[[:punct:]]", " ") On Mon, Apr 20, 2015 at 9:59 AM, Dimitri Liakhovitski wrote: > Hello! > > Please point me in the right direction. > I need to match 2 strings, but focusing ONLY on characters, ignoring > all special characters and punctuati

[R] regexpr - ignore all special characters and punctuation in a string

2015-04-20 Thread Dimitri Liakhovitski
Hello! Please point me in the right direction. I need to match 2 strings, but focusing ONLY on characters, ignoring all special characters and punctuation signs, including (), "", etc.. For example: I want the following to return: TRUE "What a nice day today! - Story of happiness: Part 2." ==