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: 
Let's take a look at your test patterns:

* `"--\*"` is actually equivalent to `"--*"` (since the `\*` is an escape sequence).
* `"--*"` will match a single `-` character, followed by zero or more `-` characters.
* `"--*.ipa"` will match a single `-` character, followed by zero or more `-` characters, followed by any single character, followed by a literal `ipa`.
* `"--\[0-9].ipa"` is actually equivalent to `"--[0-9].ipa"` (since the `\[` is an escape sequence), which will match a literal `--`, followed by a single decimal digit, followed by any single character, followed by a literal `ipa`.

However, none of these patterns would work as you used them because [`gsub`](http://ruby-doc.org/core-2.0.0/String.html#method-i-gsub) will not treat it as a regular expression:

> 
> The pattern is typically a `Regexp`; if given as a `String`, any regular expression metacharacters it contains will be interpreted literally…
> 
> 
> 

You'd need to wrap type convert your pattern to a `Regexp` (using [`Regexp.new`](http://www.ruby-doc.org/core-2.0.0/Regexp.html#method-c-new)), or use a [regular expression literal](http://www.ruby-doc.org/core-2.0.0/doc/syntax/literals_rdoc.html#label-Regular+Expressions).

Try this pattern

```
--.*

```

This pattern will find any literal `--`, followed by zero or more of any character. 

For example:

```
"app_copy--28.ipa".gsub(/--.*/, "")     # app_copy

```
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"

```