Skip to content
Prev 264774 / 398502 Next

Working with string

Happy to help.

Your interpretation is correct on the use of "\\1". This returns the value contained in the first back reference in the regex. If you wanted to return multiple back references, these would be "\\2", "\\3" and so on, each referring to successive paren pairs in the regex. Note the double backslash here because of R's treatment of the '\' character, as you may be familiar with. In most regex references, you will see '\1'.

For a basic introduction, you can look at ?regex in R to gain some insights into the construction of regular expressions. There are online references such as http://www.regular-expressions.info/ and there is also a good O'Reilly book "Mastering Regular Expressions" (http://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124).

HTH,

Marc
On Jul 7, 2011, at 12:33 PM, Bogaso Christofer wrote: