Skip to content
Prev 396132 / 398500 Next

Regexp pattern but fixed replacement?

Hi Duncan,


I only know about sub() and gsub().

There is no way to have pattern be a regular expression and replacement be
a fixed string.

Backslash is the only special character in replacement. If you need a
reference, see this file:
https://github.com/wch/r-source/blob/04650eddd6d844963b6d7aac02bd8d13cbf440d4/src/main/grep.c
particularly functions R_pcre_string_adj and wstring_adj. So just double
the backslashes in replacement and you'll be good to go.
On Thu, Apr 11, 2024, 12:36 Duncan Murdoch <murdoch.duncan at gmail.com> wrote: