Regex in atom


#1

I have this code

```{r import csv}
gpa2 <- read.csv("~/Dropbox/aktuellaKurser/651econ/datorlabbar/econA2/ddata2.csv")
```

```{r library}
library(ggplot2)
library(stargazer)
library(memisc)
library(ascii)
```

```{r results='asis'}
model1 <- lm(formula = colgpa ~ athlete, data = gpa2)
stargazer(model1, type="html")
```

But I want to have this code

<<r import csv>>
gpa2 <- read.csv("~/Dropbox/aktuellaKurser/651econ/datorlabbar/econA2/ddata2.csv")
@

<<r library>>=
library(ggplot2)
library(stargazer)
library(memisc)
library(ascii)
@

<<r results='asis'>>=
model1 <- lm(formula = colgpa ~ athlete, data = gpa2)
stargazer(model1, type="html")
@

How do I do it? I have tried with regex to
find ```{.+}
replace <<.+>>=
or with * instead of .+
But I don’t get it right.

This is relevant because I want to transition from a knitr-document to a sweave-document.


#2

You should use capture groups in the “find” field to capture the text you want to keep. Capture groups are put between parentheses, i.e. (...), and everything that is matched inside the group will be remembered for use in the replace field. Then you can use $1, $2 etc. to get back the value of group 1, 2 in the replace field. Your problem would translate to

Find: `{3}\{(.*)\} (couldn’t get discuss to render 3 consecutive backticks inside a <code> tag :stuck_out_tongue:)
Replace: <<$1>>


#3

It worked! Actually, it should be only one backtick for it to work.