On 09/25/2010 03:45 AM, Yong Wang wrote:
> dear list
> 
> I know how to store a regex expression in perl and ruby, no clue on R.
> I do read R regex manual , archives, and searched on line,
> still I need somebody help me out on how to store a regular expression
> in a variable.

A regex is just a character string in R. So, e.g.

>      str <- 'Now is the time      '
>      sub(' +$', '', str)  ## spaces only
[1] "Now is the time"
> re <- ' +$'
>      sub(re, '', str)  ## spaces only
[1] "Now is the time"

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd....@cbs.dk  Priv: pda...@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