问题
I am working in RStudio and I would like to place a certain string at the end of every selected non-empty line of a .R script.
I tried to use find and replace with regex but I am only able to select the last character of a line (using .$
) which is not helpful as I do not want to replace this character. I have tried combinations of \n\r
etc but these return no results.
I am seeking a method either to "carry" the character selected by .$
into my "replace" string (I don't think this is possible) or to select the new line and express/define a new line in my replace string.
I am neither an rstudio power-user nor a regex wizard so any help or clues are greatly appreciated.
edit: Apologies this may be a moot question. There is an April 2016 mention here that says the ability to find/replace line endings has not been implemented. Is there a way to check on progress of a feature request?
回答1:
Try the following replace all:
Find:
(.)$
Replace:
\1your_string
The quantity (.)
means to capture the last character on a given line, which is then made available in the replacement as \1
. Note that empty lines would not match, since they have no characters on them.
来源:https://stackoverflow.com/questions/45725285/how-to-find-and-replace-end-of-a-line-in-rstudio