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?
Find and Replace RStudio supports finding and replacing text within source documents: Find and replace can be opened using the Ctrl+F shortcut key, or from the Edit -> Find... menu item.
To break a line in R Markdown and have it appear in your output, use two trailing spaces and then hit return .
If you're not familiar with this feature, try it out: press Ctrl+Shift+F (MacOS: Cmd+Shift+F), or choose Find in Files… from the Edit menu. After you've done a search, switch to Replace view via the toggle, enter your new text, and click Replace All. It works with regular expressions, too.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With