[R] regular expression help
Duncan Mackay
dulcalma at bigpond.com
Fri Jun 27 02:59:29 CEST 2014
Hi
You only have a vector of length 5 and I am not quite sure of the string you
are testing
so try this
grep('[/]*\\<AARSD1\\>[/]*',test)
Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of C Lin
Sent: Friday, 27 June 2014 10:05
To: r-help at r-project.org
Subject: [R] regular expression help
Dear R users,
I need to match a string. It can be followed or preceded by whitespace or //
or nothing.
How do I code it in R?
For example:
test <- c('AARSD11','AARSD1-','AARSD1//','AARSD1 //','//AARSD1');
grep('AARSD1(\\s*//*)',test);
should return 3,4,5 and 6.
Thanks in advance for your help.
Lin
______________________________________________
R-help at 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.
More information about the R-help
mailing list