I am having trouble with a regular expression in R. The goal is to parse a Markdown/reST/knitr report text file in R to remove my own custom comments. These comments are put in the following form:
Some sentence is about something <find a citation to this>.
As Markdown uses <> for HTML tags, I need to remove these comments (with my custom function) to avoid confusion. After I do that, the sentence takes the following form:
Some sentence is about something .
Note the space between the last word and the dot. It is easy to remove that, but then the text might contain reST comments incorporating R code (knitr) with beginning with ..
:
.. {r chunk-name}
.. some R code
.. ..
So basically I need to replace the " ." in the former case, but not in the latter. I though I would achieve this using the repetition modifier of R regexp atoms:
gsub(pattern=" \\.{1}",replacement=".",x="Something ..")
[1] "Something.."
I was expecting that this expression would match a single space followed by a single (but not more) dots. However the string gets replaced regardless of whether there is one dot or two. I am a real newbie with this, so probably missing something obvious. Even so, any help will greatly appreciated.
Regards, Maxim