Question: I need to extract a number from the text as follows:

```
A<- c( '\n      0 requests\n        in 2008\n    ', '\n      1,320 requests\n        in 2008\n    ', '\n      64 requests\n        in 2008\n    ')
B<- c('John','KL', 'LK')

```

I want to get the number of requests opened from the text above. In this case I need to get the numbers 

```
A       C
John    0
KL      1,320
LK      64

```

any suggestion on how to extract this varying length substring? Thanks so much

Answer: 
You can do:

```
library(stringr)
y <- do.call(rbind, lapply(A, function(x){str_extract_all(x,"\\(?[0-9,.]+\\)?")[[1]]}))
setNames(as.data.frame(cbind(B,y[,1])), c("A", "C"))

> setNames(as.data.frame(cbind(B,y[,1])), c("A", "C"))
     A     C
1 John     0
2   KL 1,320
3   LK    64

```
```
transform(read.table(text=gsub("\\n?\\s+",";",A),sep=";",fill = T),V1=B)[1:2]

    V1    V2
1 John     0
2   KL 1,320
3   LK    64

```