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"

```
You may try these gsub functions.

```
> gsub("[^\\d-]", "", x, perl=T)
[1] "123-456-789"
> gsub(".*\\(|\\)", "", x)
[1] "123-456-789"
> gsub("[^0-9-]", "", x)
[1] "123-456-789"

```

Few more...

```
> gsub("[0-9-](*SKIP)(*F)|.", "", x, perl=T)
[1] "123-456-789"
> gsub("(?:(?![0-9-]).)*", "", x, perl=T)
[1] "123-456-789"

```