Question: I have a string:

```
app_copy--28.ipa

```

The result I want is:

```
app_copy

```

The number after `--` could be of variable length, so I want to match everything including and after `--`.

I've tried a few patterns, but none are matching for some reason:

```
gsub("--\*", "")
gsub("--*", "")
gsub("--*.ipa", "")
gsub("--\[0-9].ipa", "")

```

What am I missing?

Answer: 
Don't use `gsub` to try to change the string, simply use a pattern to match the part you want:

```
"app_copy--28.ipa"[/^(.+?)--/, 1] # => "app_copy"

```

String's [`[]`](http://ruby-doc.org/core-2.0.0/String.html#method-i-5B-5D) takes a lot of different types of parameters. You can pass in a pattern, and the index of the capture that you want, to extract just that part. From the documentation:

```
str[regexp, capture] → new_str or nil

```

> 
> If a Regexp is supplied, the matching portion of the string is returned. If a capture follows the regular expression, which may be a capture group index or name, follows the regular expression that component of the MatchData is returned instead.
> 
> 
>
How is this ?

```
str = "app_copy--28.ipa"
str[0..str.index("-")-1]
# => "app_copy"

str = "app_copy--28.ipa"
str.split("--").first
# => "app_copy"

```