this should do what you want:
> myexstrings = c("*AAA.AA","BBB BB","*.CCC.","**dd- d") > a = gsub("^\\W*","", myexstrings,perl=T) > b = gsub("\\W.*", "", a, perl=T) > b
first one, removes any non-word characters from the beginning (as you
already figured out)
second one, removes any remaining non-word characters AND everything following.
on 06/27/2008 06:23 AM Tom.O said the following:
> Hi R gurus
> I have a matching problem that I cant solve. I have tried multiple solutions
> and searched varius help-sites but I cant get it to work.
> This is the problem
> myexstrings = c("*AAA.AA","BBB BB","*.CCC.","**dd- d")
> what I want do do is to remove any non-characters in the beginning and
> everything else after the non-character symbol after the first set of
> characters so that the string becomes:
> I can figure out the start, sub("^\\W*","", myexstrings,perl=T) will remove
> the unwanted beginnings but then its the rest.
> And please no links to any helppages, I have been looking at most of them
> for the last hour without any success.
Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Archive generated by hypermail 2.2.0, at Fri 27 Jun 2008 - 14:31:35 GMT.
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.
list of date sections of archive