How to find and replace end of a line in RStudio

让人想犯罪 __ 提交于 2020-07-05 06:51:04

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!