Ramya -
   Try

strings = c('UV7C11-F9-E1 MCS#9831019','MCS Lot #9512516')
sub('^.*?(\\d{5,}).*?$','\\1',strings,perl=TRUE)
[1] "9831019" "9512516"

The regular expression finds the first string of five or more numbers in the strings. Since you said the numbers could occur anywhere in the string, you could have provided some examples where the numbers weren't the last part of the string.

                                        - Phil Spector
                                         Statistical Computing Facility
                                         Department of Statistics
                                         UC Berkeley
                                         spec...@stat.berkeley.edu


On Mon, 7 Dec 2009, Ramya wrote:


Hi  there

I have a string like this i want to extract 9831019 from this string i used
a regular expresion \d+ by which i can only make it to see 7 and returns.
This type of number(9831019)  appears in any part of the string and is
definitely more than 5 digits all the time and i want to give that as a
condition

UV7C11-F9-E1 MCS#9831019
MCS Lot #9512516"


how do i go abt it

Ramya
--
View this message in context: 
http://n4.nabble.com/Regular-expression-help-tp954834p954834.html
Sent from the R help mailing list archive at Nabble.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.


______________________________________________
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