Re: [R] Problem with the str_replace function

2021-03-17 Thread phil
Your help is much appreciated. I now understand what my problem was and can move forward. Philip On 2021-03-17 01:19, Hervé Pagès wrote: Hi, stringr::str_replace() treats the 2nd argument ('pattern') as a regular expression and some characters have a special meaning when they are used in a

Re: [R] Problem with the str_replace function

2021-03-16 Thread Hervé Pagès
Hi, stringr::str_replace() treats the 2nd argument ('pattern') as a regular expression and some characters have a special meaning when they are used in a regular expression. For example the dot plays the role of a wildcard (i.e. it means "any character"): > str_replace("aaXcc", "a.c",

Re: [R] Problem with the str_replace function

2021-03-16 Thread Bert Gunter
I prefer using regular expressions directly, so this may not satisfy you: > a <-"Women's footwear (excluding athletic)" > b <- gsub("(.*) \\(.*$","\\1",a) > b [1] "Women's footwear" There are, of course other ways to do this with regex's or even substring() Bert Gunter "The trouble with having

[R] Problem with the str_replace function

2021-03-16 Thread phil
I have a problem with the str_replace() function in the stringr package. Please refer to my reprex below. I start with a vector of strings, called x. Some of the strings contain apostrophes and brackets. I make a simple replacement as with x1, and there is no problem. I make another simple