Question: How can I remove spaces, a keyword, and everything after it? Here's what I'm looking for

```
var test = $('.replaceMe').attr('title').replace(/ /g, '');

<a class="replaceMe" href="#" title="Replace By Everything After It">haha</a>

```

resulting in:

```
test = Replace;

```

---

UPDATE:

The keyword is a yet-to-be-determined word that will be included in all titles. In this example, it is "By".

Both Roko and user1215106's answers work- in that they remove all the excess from the example, leaving Replace, but I failed to clarify that the phrase before the keyword (in this case, Replace) will vary and will have differing amounts of words.

For example:

```
title="Replace By Everything After It"

Result= Replace

title="All This Should Stay By Things That Should Go"

Result= AllThisShouldStay

```

Answer: 
```
var test = $('.replaceMe').attr('title').replace(/\s+by\s.*/, '').replace(/\s+/. ''); 

```
Let `key` be the keyword you want to find.

```
escapedKey = key.replace(/([-$^&*()\/\\+?.\[\]{}|])/g, "\\$1");
$('.replaceMe').attr('title').replace(new RegExp(escapedKey + ".*"), "")

```

I tried to generalize for arbitrary keyword, but not yet tested for everything.