On Wed, 3 Apr 2019 15:01:37 +0100
Graham Leask via R-help <r-help@r-project.org> wrote:

Suppose that `BHC$Date` contains a string "M_24".

You do:

> BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date , "M_2" ,
> "01-04-2017"))

before you have a chance to do:

> BHC <-BHC %>% mutate ( Date = stringr :: str_replace ( Date ,
> "M_24" , "01-02-2019"))

So now it has "01-04-20174" because the first expression had a
successful match and already made a replacement.

help() for stringi::stringi-search-regex says that look-around
expressions are supported, so one of the ways to prevent this would be
to modify your patterns to look like e.g. 'M_2(?!\\d)' to match
'M_2' that is *not* followed by a digit.

-- 
Best regards,
Ivan

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to