I am trying to replace instances in a string which begin with abc
in a text I'm working with in R. The output text is highlighted in HTML over a couple of passes, so I need the replacement to ignore text inside HTML carets.
The following seems to work in Python but I'm not getting any hits on my regex in R. All help appreciated.
test <- 'abcdef abc<span abc>defabc abcdef</span> abc defabc'
gsub('\\babc\\(?![^<]*>\\)', 'xxx', test)
Expected output:
xxxdef xxx<span abc>defabc xxxdef</span> xxx defabc
Instead it is ignoring all instances of abc
.