On Wed, Jul 25, 2012 at 4:34 PM, mdvaan <mathijsdev...@gmail.com> wrote:
> Thanks Gabor. That worked really well. I have been reading about the use of
> POSIX and regular expressions and I tried to use your example to see if I
> could  ignore all matches in which the character preceding (rather than
> following) the match is one of [:alpha:]? So far, I have been unsuccessful.
> Could anyone help me out here or direct me to a source that explains the
> combined use of POSIX and regular expressions? Thanks!
>

We match the start of the string or a non-alpha followed by the
desired string (here its xx).  Because we want the second back
reference (the default is to return the first back rerference if the
function is omitted) we must specifically tell it that by using a
function which returns its second argument, e.g. function(x, y) y or
function(...) ..2 or using the equivalent formula notation just ~ ..2
:

strapply(c("cxx", "xxc", "xx", " xx"), "(^|[^[:alpha:]])(xx)", ~ ..2)


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to