Suppose I have a string like "A B C (123-456-789)", I'm wondering what's the best way to retrieve "123-456-789" from it. 

```
strsplit("A B C (123-456-789)", "\\(")
[[1]]
[1] "A B C" "123-456-789)"

```
['https://Stackoverflow.com/questions/31292853', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3015453/']
or with `sub` from `base R`:

```
sub("[^(]+\\(([^)]+)\\).*", "\\1", "A B C (123-456-789)")
#[1] "123-456-789"

```

Explanation:

`[^(]+` : matches anything except an opening bracket  

`\\(` : matches an opening bracket, which is just before what you want  

`([^)]+)` : matches the pattern you want to capture (which is then retrieved in `replacement="\\1"`), which is anything except a closing bracket  

`\\).*` matches a closing bracket followed by anything, 0 or more times

***Another option with look-ahead and look-behind***

```
sub(".*(?<=\\()(.+)(?=\\)).*", "\\1", "A B C (123-456-789)", perl=TRUE)
#[1] "123-456-789"

```
Try this also: 

```
 k<-"A B C (123-456-789)"
     regmatches(k,gregexpr("*.(\\d+).*",k))[[1]]
[1] "(123-456-789)"

```

With suggestion from @Arun: 

```
regmatches(k, gregexpr('(?<=\\()[^A-Z ]+(?=\\))', k, perl=TRUE))[[1]]

```

With suggestion from @akrun: 

```
regmatches(k, gregexpr('[0-9-]+', k))[[1]]

```